New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rounding when converting float tuple to str #51259
Comments
When a floating point value is stored, the actual value stored is '''Shows that floats in tuples are not rounded like floats.
>>> print(.1)
0.1
>>> print((.1,))
(0.10000000000000001,)
'''
import doctest
doctest.testmod(verbose=True) |
What OS, processor, and Python version are you running this code on? From your example, it's Python 3.x. 3.1 has a completely rewritten >>> print(.1)
0.1
>>> print((.1,))
(0.1,)
>>> For 2.6 and 3.0, you'll get the old behavior, and this won't change. Are |
This is expected (and correct) behaviour for Python 2.x and 3.0. Note Python 2.6.2 (r262:71600, Aug 26 2009, 09:40:44)
[GCC 4.2.1 (SUSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> str(.1)
'0.1'
>>> repr(.1)
'0.10000000000000001'
>>> str((.1,))
'(0.10000000000000001,)'
>>> tuple(str(x) for x in (.1,))
('0.1',) |
And as Eric says, you shouldn't see this behaviour in Python 3.1, since |
I tried Python 3.1, and it does indeed not have this issue. Thanks for |
You're seeing the difference between str(.1) and repr(.1). When This is easily seen with a number like pi: >>> from math import *
>>> print(pi)
3.14159265359
>>> print((pi,))
(3.141592653589793,)
>>> repr(pi)
'3.141592653589793'
>>> str(pi)
'3.14159265359' In Py3.1, the repr computation was changed to show the shortest string |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: