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: float() not accurate
Type: Stage:
Components: Interpreter Core Versions: Python 2.4
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: dols, nascheme
Priority: normal Keywords:

Created on 2005-06-16 18:00 by dols, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg25558 - (view) Author: Brian Dols (dols) Date: 2005-06-16 18:00
float("4.1") returns 4.0999999999996

shouldn't it return 4.1?
msg25559 - (view) Author: Neil Schemenauer (nascheme) * (Python committer) Date: 2005-06-16 18:27
Logged In: YES 
user_id=35752

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 more information:

http://www.python.org/doc/2.2.1/tut/node14.html
History
Date User Action Args
2022-04-11 14:56:11adminsetgithub: 42090
2005-06-16 18:00:52dolscreate