-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Confusing float formatting for empty presentation type. #50170
Comments
I think the change in precision in the following is surprising, and should Python 3.1a2+ (py3k:72258:72259, May 4 2009, 11:49:27)
[GCC 4.0.1 (Apple Inc. build 5490)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> '{}'.format(10/3.)
'3.33333333333'
>>> '{:}'.format(10/3.)
'3.33333333333'
>>> '{:13}'.format(10/3.)
' 3.33333'
>>> '{:-}'.format(10/3.)
'3.33333' Notice that the first two results above give 12 digits of precision, The above behaviour can be explained by a close reading of PEP-3101. """similar to 'g', except that it prints at least one digit after the along with the fact that for 'g', the default precision is 6. The first """For all built-in types, an empty format specification will produce the and the fact that str(float) uses a precision of 12. To me, it seems wrong, and potentially confusing, that adding a field One possible solution would be to have the empty presentation type always |
Here's a patch, that also changed complex formatting in the same way. |
About your patch: Wouldn't it make more sense to switch to type 's', Or, also switch float_str to use 'g' with a precision of |
Yes, that makes some sense. How would you handle
This sounds good to me. It does feel as though there's unnecessary |
Good point, I hadn't thought of that. I'm not a big fan of switching
A major point of 's' was to not specify the precision, so I'd prefer to |
Let's do that then. I'll update the patch. |
Updated patch, that removes the 's' type code. |
I've reviewed this and it looks good. I'll check it in to py3k shortly. |
Committed in py3k r72333 and trunk r72348. I also updated the |
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: