round(22.47,2) gives 22.469999999999999?
sjmachin at lexicon.net
Fri Aug 8 00:37:58 CEST 2003
Bernhard Herzog <bh at intevation.de> wrote in message news:<6qn0elr99k.fsf at salmakis.intevation.de>...
> 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)
> >>> round(-1.9)
"Fail" depends on your/his definition of "round to an int" -- up?
down? towards zero? away from zero? closest in either direction [ties
More information about the Python-list