# Rough draft: Proposed format specifier for a thousands separator

Ulrich Eckhardt eckhardt at satorlaser.com
Thu Mar 12 10:30:16 CET 2009

```Raymond Hettinger wrote:
>> The idea is to make numbering formatting a little easier with
>> the new format() builtin:
>> http://docs.python.org/library/string.html#formatspec
[...]
> Scanning the web, I've found that thousands separators are
> usually one of COMMA, PERIOD, SPACE, or UNDERSCORE.  The
> COMMA is used when a PERIOD is the decimal separator.
>
> James Knight observed that Indian/Pakistani numbering systems
> group by hundreds.   Ben Finney noted that Chinese group by
> ten-thousands.

IIRC, some cultures use a non-uniform grouping, like e.g. "123 456 78.9".
For that, there is also a grouping reserved in the locale (at least in
those of C++ IOStreams, that is). Further, an that seems to also be one of
your concerns, there are different ways to represent negative numbers like
e.g. "(123)" or "-456".

> Make both the thousands separator and decimal separator user
> specifiable but not locale aware.  For simplicity, limit the
> choices to a comma, period, space, or underscore.
>
> [[fill]align][sign][#][0][minimumwidth][T[tsep]][dsep precision][type]
>
> Examples:
>
>   format(1234, "8.1f")    -->     '  1234.0'
>   format(1234, "8,1f")    -->     '  1234,0'
>   format(1234, "8T.,1f")  -->     ' 1.234,0'
>   format(1234, "8T .f")   -->     ' 1 234,0'
>   format(1234, "8d")      -->     '    1234'
>   format(1234, "8T,d")    -->     '   1,234'

format(1234, "8.1", tsep=",")
--> ' 1,234.0'
format(1234, "8.1", tsep=".", dsep=",")
--> ' 1.234,0'
format(123456, tsep=" ", grouping=(3, 2,))
--> '1 234 56'

IOW, why not explicitly say what you want using keyword arguments with
Seriously, the problem I see with this proposal is that its aim to be as
short as possible actually makes the resulting format specifications
unreadable. Could you even guess what "8T.,1f" should mean if you had not
written this?

> This proposal meets mosts needs (except for people wanting
> grouping for hundreds or ten-thousands), but iIt comes at the
> expense of being a little more complicated to learn and
> remember.

Too expensive for my taste.

Uli

--
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

```