[Tutor] The '45' bug in round()
Michael Hannon
jmh at physics.ucdavis.edu
Tue Mar 20 16:31:17 CET 2007
On Tue, Mar 20, 2007 at 04:09:49AM -0700, Dick Moores wrote:
> At 11:00 AM 3/19/2007, Michael Hannon wrote:
> >On Mon, Mar 19, 2007 at 03:04:03AM -0700, Dick Moores wrote:
> >> Yesterday I was shocked, SHOCKED, to discover that round() is
> >> occasionally rounding incorrectly. For example,
> >>
> >> >>> print round(0.19945,4)
> >> 0.1994
> >.
> >.
> >.
> >> Comments, Tutors? Am I way out in left field with this?
> >
> >
> >I suggest you might want to look at the discussion of unbiased rounding at:
> >
> > http://en.wikipedia.org/wiki/Rounding
>
> Thanks. I'm familiar with "unbiased rounding". I'm glad to know about
> that Wikipedia article. Could you tell me what, in particular, you
> wanted me to think about?
Well, perhaps this is something for me to think about, but if you had asked
me to round 0.19945 to four decimal places, I would have told you the answer
is 0.1994, i.e., the same answer that Python gives.
- Mike
More information about the Tutor
mailing list