Help me please : Rounding-down numbers

Skip Montanaro skip at pobox.com
Thu Mar 27 01:30:32 CET 2003


    joseph> I have a floating number which I need to "round-down" to the
    joseph> nearest whole number. I am doing this by type-casting it as an
    joseph> "int". Would this work all the time ? 

It should.

There is also the floor() function in the math module:

    >>> math.floor(4.71)
    4.0
    >>> int(4.71)
    4
    >>> 4.71 - int(4.71)
    0.70999999999999996
    >>> 4.71 - math.floor(4.71)
    0.70999999999999996

Skip





More information about the Python-list mailing list