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.

Author eric.smith
Recipients eric.smith, mark.dickinson, rhettinger
Date 2009-03-19.00:33:54
SpamBayes Score 2.7173264e-12
Marked as misclassified No
Message-id <1237422838.11.0.502789865949.issue5515@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2009-03-19 00:33:58eric.smithsetrecipients: + eric.smith, rhettinger, mark.dickinson
2009-03-19 00:33:58eric.smithsetmessageid: <1237422838.11.0.502789865949.issue5515@psf.upfronthosting.co.za>
2009-03-19 00:33:56eric.smithlinkissue5515 messages
2009-03-19 00:33:55eric.smithcreate