[Tutor] The '45' bug in round()
Dick Moores
rdm at rcblue.com
Tue Mar 20 22:37:15 CET 2007
At 02:24 PM 3/20/2007, Terry Carroll wrote:
>On Tue, 20 Mar 2007, Dick Moores wrote:
>
> > >>> print round(0.19965, 4)
> > 0.1997
> >
> > (which rounds up to an odd number, 7)
>
>Now that's weird. It should (I say) round to .1996; not because 6 is even
>and 7 is not[1], but because 0.19965 is actually closer to 0.1996 than to
>0.1997:
>
> >>> 0.19965
>0.19964999999999999
>
>
>[1] The Python rounding rule is to round "away from zero," i.e., to round
>up for positive numbers and down (where "down" means "more negative") for
>negative numbers.
So you're claiming there's a bug in round()? So was I, the OP, in
that original post, but a bug of a different sort. ;)
Dick Moores
More information about the Tutor
mailing list