Rounding

John Machin sjmachin at lexicon.net
Tue Dec 18 15:51:03 EST 2007


On Dec 19, 7:21 am, "Ron Provost" <ron.lo... at cox.net> wrote:
> Adding 0.5, then converting to an int always works for me.
>
> >>> x = 6.345
> >>> int( x + 0.5 )
> >>> 6

Always?

>>> x = -6.345
>>> int(x + 0.5)
-5
>>>

I therefore deduce that you have never crossed the equator :-)

Be careful, doing that can be dangerous:
    http://catless.ncl.ac.uk/Risks/3.44.html#subj1.1



More information about the Python-list mailing list