[Python-bugs-list] [ python-Bugs-426711 ] Floating Point Curiosity in Python 2.1
noreply@sourceforge.net
noreply@sourceforge.net
Wed, 23 May 2001 11:33:43 -0700
Bugs item #426711, was updated on 2001-05-23 11:27
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=426711&group_id=5470
Category: None
>Group: Not a Bug
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: Daniel Graham (danielgraham)
Assigned to: Nobody/Anonymous (nobody)
Summary: Floating Point Curiosity in Python 2.1
Initial Comment:
[GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-81)] on
linux 2
In python 2.1 in python 1.5.2
>>> .10*103
10.300000000000001 10.3
>>>round(.10*103,2)
10.300000000000001 10.3
>>>round(.10*103.123,1)
10.300000000000001 10.3
>>>round(.10*103.123,2)
10.31 10.31
>>>round(.0*103.123,3)
10.311999999999999 10.312
----------------------------------------------------------------------
Comment By: Tim Peters (tim_one)
Date: 2001-05-23 11:33
Message:
Logged In: YES
user_id=31435
This is not a bug.
Binary floating point cannot represent decimal fractions exactly,
so some rounding always occurs (even in Python 1.5.2).
What changed is that Python 2.0 shows more precision than before
in certain circumstances (repr() and the interactive prompt).
You can use str() or print to get the old, rounded output:
>>> print 0.1+0.1
0.2
>>>
Follow the link for a detailed example:
http://www.python.org/cgi-bin/moinmoin/RepresentationError
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=426711&group_id=5470