round() function strange behaviour

Tim Peters tim.one at comcast.net
Sat Mar 9 21:07:39 EST 2002


[brobbins333 at shaw.ca]
> the round() function will sometimes return a predictable result, as
> in:
>
> round(45.67891, 2)
> >>> 45.68
>
> but sometimes it will return something like:
> 
> round(56.78923, 2)
> >>> 56.789999999999999
> 
> 2.1 and 2.2 both behave this way on two different (Windows) computers.
> What's going on here?

Also on Linix, Mac, etc computers.  See

    http://www.python.org/doc/current/tut/node14.html

round() usually does the best job that can be done.




More information about the Python-list mailing list