round function error???
Terry Reedy
tjreedy at udel.edu
Fri Jul 18 18:15:48 EDT 2008
Anthony wrote:
> Isn't this a mistake???
>
>>>> round(3499.349439034,44)
> 3499.3494390340002
>>>> round(_,2)
> 3499.3499999999999
>>>> round(_,1)
> 3499.4000000000001
>
> My Python 2.5.1 spat that out..
No, round() return binary floats that, in general, cannot represent
decimal floats exactly. Formatted printing gives what you expect.
>>> '%8.2f' % x
' 3499.35'
More information about the Python-list
mailing list