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 addition rounding error
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: eitan.adler, rhettinger, voidptr
Priority: normal Keywords:

Created on 2018-05-27 03:38 by voidptr, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg317779 - (view) Author: voidptr (voidptr) Date: 2018-05-27 03:38
help

in python 3.6.5
z = 1787.4 + 6.2
gives me z = 1793.600000000001

in python 2.7.15
gives z = 1793.6

I dont want explicitly round float thing every time so I went back to 
2.7.15....
msg317780 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2018-05-27 04:17
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'
History
Date User Action Args
2022-04-11 14:59:00adminsetgithub: 77838
2018-05-27 04:17:04rhettingersetstatus: open -> closed

nosy: + rhettinger
messages: + msg317780

resolution: not a bug
stage: resolved
2018-05-27 03:44:15eitan.adlersetnosy: + eitan.adler
2018-05-27 03:38:09voidptrcreate