in reply to Rounding a number?

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re^2: Rounding a number?
by wazoox (Prior) on Jun 09, 2005 at 10:47 UTC
    This isn't right, because
    print int(28.1+1)
    will give 29 too...
    If he wants to round greater than .5 to the next unit, the simple thing to do is
    print int(28.1+.5)

      Rounding != truncation

      How can you feel when you're made of steel? I am made of steel. I am the Robot Tourist.
      Robot Tourist, by Ten Benson

      Of course it will the same, if you use '+1" to it.
      That is why i present the plain 'int', using the same number (28.9) to show him that no matter what you have after the '.' it will round it to the smaller number.
      so if you add 1 to it, only then it will round it to the bigger number.
      Is it so hard to understand this?
      of course, if he has more than one numbers in variables, and he wants to check them, he will use '+.5' .
      I just gave him an easy way to do what he want..
      Sorry, i though i wouldn't have to explain such a simple thing

      ``The wise man doesn't give the right answers, he poses the right questions.'' TIMTOWTDI
        It's certainly very easy to understand for you and for me, but it may be not for the one who asked first. So I feel like you really had to explain it after all :)
        ummm, well... er...; unless there's an invisible decimal point I can't see, parents discussing addition of ONE are not responsive.

        If one adds 1 (TEN/TENTHS), of course it evals as the next higher number; the example might be more precise if the discussion were about adding ONE/TENTH, 0.1 or adding FIVE/TENTHS (0.5) save for the fact that it just doesn't work that way:

        C:\>perl -e "print (28.6)"
        28.6
        
        C:\>perl -e "print (28.1)"
        28.1
        
        w2k, This is perl, v5.8.6 built for MSWin32-x86-multi-thread (with 3 registered patches, see perl -V for more detail)