round(22.47,2) gives 22.469999999999999?

Bernhard Herzog bh at intevation.de
Thu Aug 7 07:34:47 EDT 2003


sjmachin at lexicon.net (John Machin) writes:

>> Wouldn't
>> 
>> int(22.47 + .5)
>> 
>> get you to where you want to go?
>
> Sure would, if 22 was where you wanted to go.

Even if he would want to round to an int, using int(x + 0.5) would fail
for negative values:

>>> int(-1.9 + 0.5)
-1

but

>>> round(-1.9)
-2.0


   Bernhard

-- 
Intevation GmbH                                 http://intevation.de/
Sketch                                 http://sketch.sourceforge.net/
Thuban                                  http://thuban.intevation.org/




More information about the Python-list mailing list