This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Floating point is broken in Python 2.0
Type: Stage:
Components: IDLE Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: invader8, tim.peters
Priority: normal Keywords:

Created on 2000-12-21 12:03 by anonymous, last changed 2022-04-10 16:03 by admin. This issue is now closed.

Messages (4)
msg2727 - (view) Author: Nobody/Anonymous (nobody) Date: 2000-12-21 12:03
Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.6 -- press F1 for help
>>> p=0.6
>>> p
0.59999999999999998
>>> 
msg2728 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2000-12-21 16:15
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
msg2729 - (view) Author: Michael Donegan (invader8) Date: 2002-05-06 17:10
Logged In: YES 
user_id=537045

This is still a problem in
Python 2.2 (#1, Dec 31 2001, 15:21:18)

It is a bug. Why would we expect that
the interactive prompt would behave
differently (worse) from using print?
msg2730 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2002-05-06 18:04
Logged In: YES 
user_id=31435

You may not like it, but it's not a bug.  Read the docs for 
a detailed explanation:

http://www.python.org/doc/current/tut/node14.html
History
Date User Action Args
2022-04-10 16:03:34adminsetgithub: 33624
2000-12-21 12:03:15anonymouscreate