round function problem

Gregory Bond gnb at itga.com.au
Tue Sep 6 10:02:48 CEST 2005


mg wrote:

> Is it a bug or a control behavour ? I don't understand ?!?!?!?!...

It's a case of applying different float-to-text rounding in different 
situations, on a variable that (even after round()) is not representable 
in binary floatingpoint.

"print var" does one sort of string conversion (using str()), "print 
[var]" does another type (using repr() on the list element).  The 
underlying value is the same, it's just printed differently.

>>>> var = round(0.5**0.5, 2)
>>>> var
> 0.70999999999999996
>>>> print var
> 0.71
>>>> print [var]
> [0.70999999999999996]
>>>> print str(var)
> 0.71
>>>> print repr(var)
> 0.70999999999999996
>>>> 






More information about the Python-list mailing list