[issue33657] float addition rounding error

Raymond Hettinger report at bugs.python.org
Sun May 27 00:17:04 EDT 2018


Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:

The math hasn't changed.  The underlying values haven't changed.  What did change what that the __str__ now displays to full precision.  Formerly, it used to display a rounded result that didn't reflect the actual stored value.

$ python2.7
Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 29 2018, 20:59:26)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> z = 1787.4 + 6.2
>>> repr(z)
'1793.6000000000001'
>>> str(z)
'1793.6'

$ python3.6
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 03:03:55)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> z = 1787.4 + 6.2
>>> repr(z)
'1793.6000000000001'
>>> str(z)
'1793.6000000000001'

----------
nosy: +rhettinger
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33657>
_______________________________________


More information about the Python-bugs-list mailing list