[Python-bugs-list] [Bug #122327] 0.1 + 0.1 = 0.20000000000000001

noreply@sourceforge.net noreply@sourceforge.net
Mon, 13 Nov 2000 12:34:03 -0800


Bug #122327, was updated on 2000-Nov-13 09:28
Here is a current snapshot of the bug.

Project: Python
Category: Core
Status: Closed
Resolution: None
Bug Group: None
Priority: 5
Summary: 0.1 + 0.1 =  0.20000000000000001

Details: I am running Python 2.0 on solaris 8 and I am getting this bug.  I thought that this was fixed.

>>> 0.1 + 0.1
0.20000000000000001
>>> a = 0.1 + 0.1
>>> print a
0.2
>>> a
0.20000000000000001
>>>


Follow-Ups:

Date: 2000-Nov-13 12:34
By: gvanrossum

Comment:
This is not  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
>>>
-------------------------------------------------------

For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=122327&group_id=5470