[Tutor] The '45' bug in round()

Michael Hannon jmh at physics.ucdavis.edu
Tue Mar 20 18:17:02 CET 2007


On Tue, Mar 20, 2007 at 09:03:43AM -0700, Dick Moores wrote:
.
.
.
> >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.
> 
> Is this because that rounding conforms to "unbiased rounding"? If so, 
> then you won't like
> 
> >>> print round(0.19965, 4)
> 0.1997
> 
> (which rounds up to an odd number, 7)

Heh.  You're right.  I don't.  If I get some time, I'll try to dig
through the Python source code to see what they're doing.  Thanks.

					- Mike


More information about the Tutor mailing list