[Python-bugs-list] [ python-Bugs-476435 ] inconsistant behavior with float and str
noreply@sourceforge.net
noreply@sourceforge.net
Tue, 30 Oct 2001 11:58:15 -0800
Bugs item #476435, was opened at 2001-10-30 10:52
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=476435&group_id=5470
>Category: Python Interpreter Core
>Group: Not a Bug
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: Brian Hoenig (rambozo)
>Assigned to: Tim Peters (tim_one)
Summary: inconsistant behavior with float and str
Initial Comment:
>>> 1.1
1.1000000000000001
>>> str(1.1)
'1.1'
>>> str(1.1000000000000001)
'1.1'
>>>
This happens on 2.1.1 on Linux and win32.
There seem to be several issues here.
----------------------------------------------------------------------
Comment By: Tim Peters (tim_one)
Date: 2001-10-30 11:58
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 more information:
http://python.sourceforge.net/devel-docs/tut/node14.html
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=476435&group_id=5470