round(22.47,2) gives 22.469999999999999?
John Machin
sjmachin at lexicon.net
Thu Aug 7 18:37:58 EDT 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)
> -1
>
> but
>
> >>> round(-1.9)
> -2.0
>
>
> Bernhard
"Fail" depends on your/his definition of "round to an int" -- up?
down? towards zero? away from zero? closest in either direction [ties
broken how?]?
More information about the Python-list
mailing list