Message83797
I think the way leading zero padding is handled for int and float by
format's 'n' code is a bug.
>>> import locale
>>> locale.setlocale(locale.LC_ALL, 'en_US.UTF8')
'en_US.UTF8'
>>> format(12345, '010n')
'000012,345'
>>> format(12345, '09n')
'00012,345'
>>> format(12345, '08n')
'0012,345'
>>> format(12345, '07n')
'012,345'
>>> format(12345, '06n')
'12,345'
When 'n' support was added to Decimal, leading zeros had commas in them:
>>> from decimal import Decimal
>>> format(Decimal(12345), '010n')
'00,012,345'
>>> format(Decimal(12345), '09n')
'0,012,345'
>>> format(Decimal(12345), '08n')
'0,012,345'
>>> format(Decimal(12345), '07n')
'012,345'
>>> format(Decimal(12345), '06n')
'12,345'
Decimal also has the same support for PEP 378's ',' modifier:
>>> format(Decimal(12345), '010,')
'00,012,345'
>>> format(Decimal(12345), '09,')
'0,012,345'
>>> format(Decimal(12345), '08,')
'0,012,345'
>>> format(Decimal(12345), '07,')
'012,345'
>>> format(Decimal(12345), '06,')
'12,345'
>>>
As I'm implementing PEP 378 for int and float, I'm going to make it work
the same way that Decimal works. For consistency, and because I think
the current behavior is not useful, I'd like to change float and int
formatting with 'n' to match Decimal and PEP 378 for the ',' modifier.
Since I consider this a bug, I'd like to consider backporting it to 2.6
and 3.0, if the changes aren't too intrusive. |
|
Date |
User |
Action |
Args |
2009-03-19 00:33:58 | eric.smith | set | recipients:
+ eric.smith, rhettinger, mark.dickinson |
2009-03-19 00:33:58 | eric.smith | set | messageid: <1237422838.11.0.502789865949.issue5515@psf.upfronthosting.co.za> |
2009-03-19 00:33:56 | eric.smith | link | issue5515 messages |
2009-03-19 00:33:55 | eric.smith | create | |
|