[Python-ideas] Rough draft: Proposed format specifier for a thousands separator (discussion moved from python-dev)

Greg Ewing greg.ewing at canterbury.ac.nz
Tue Mar 17 12:04:34 CET 2009


Mark Dickinson wrote:
> The PEP specifies that format(1234, "08,d")
> should give '0001,234', but that's something of a special case:
> ',001,234' isn't really a viable alternative.

Both of those look equally unviable to me. I don't
think I'd ever use zero filling together with commas
myself, as it looks decidedly weird, but if I had
to pick a meaning for format(1234, "08,d") I think
I would make it

   ' 001,234'

the reasoning being that since a comma falls on the
first position of an 8-char field, you can never
put a digit there, and putting a comma at the
beginning is no use.

If there are more than 6 digits, then you get a
comma plus an extra digit, making the field overflow
to 9 characters, e.g. format(1234567, "08,d") gives

  '1,234,567'

-- 
Greg



More information about the Python-ideas mailing list