[ python-Bugs-1222098 ] float() not accurate

SourceForge.net noreply at sourceforge.net
Thu Jun 16 20:27:12 CEST 2005


Bugs item #1222098, was opened at 2005-06-16 18:00
Message generated for change (Comment added) made by nascheme
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1222098&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Type/class unification
Group: Python 2.4
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: Brian Dols (dols)
Assigned to: Nobody/Anonymous (nobody)
Summary: float() not accurate

Initial Comment:

float("4.1") returns 4.0999999999996

shouldn't it return 4.1?


----------------------------------------------------------------------

Comment By: Neil Schemenauer (nascheme)
Date: 2005-06-16 18:27

Message:
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

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1222098&group_id=5470


More information about the Python-bugs-list mailing list