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
locale.format() problems with decimal separator #46774
Comments
locale.format() doesn't insert correct decimal separator to string Python 2.4.5 (#2, Mar 12 2008, 14:42:24)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.setlocale(locale.LC_ALL, "ru_RU.UTF-8")
'ru_RU.UTF-8'
>>> a = 1.234
>>> print locale.format("%f", a)
1,234000
>>> print locale.format("%f\n", a)
1,234000
>>> print locale.format("%f\r", a)
1,234000
Python 2.6a1+ (trunk:62083, Mar 31 2008, 19:24:56)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu6)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.setlocale(locale.LC_ALL, "ru_RU.UTF-8")
'ru_RU.UTF-8'
>>> a = 1.234
>>> print locale.format("%f", a)
1,234000
>>> print locale.format("%f\n", a)
1.234000
>>> print locale.format("%f\r", a)
1.234000
Python 2.5.2 (r252:60911, Mar 12 2008, 13:36:25)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.setlocale(locale.LC_ALL, "ru_RU.UTF-8")
'ru_RU.UTF-8'
>>> a = 1.234
>>> print locale.format("%f", a)
1,234000
>>> print locale.format("%f\n", a)
1.234000
>>> print locale.format("%f\r", a)
1.234000 |
I've uploaded a patch that fixes this concrete issue, though |
This bug is more subtle than it first appears. As far as I've been able See if last character of formatted string is different from last char of Make sure last character of format string is a valid format character: Check for a decimal in the formatted string and if it didn't get One could argue that at least \n and \r should be checked for since the To fix this correctly would require reimplementing format parsing in the I'm inclined to close this "won't fix", unless someone can come up with |
AFAIK, locale.format() is supposed to be used with a single format |
That is true, however the code contains the comment "this is only for |
It occured to me last night that it could be checked using a regular I added georg.brandl to the nosy list since svn blame shows him as the |
Nice to see this moving forward. Your patch looks nicer than my naive |
Fixed in r70936/r70938. |
Hmm. See bug 10379 for fallout from this change. I'm not saying it should be reverted but see that issue for further discussion. |
I mean bpo-10379 |
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: