Rough draft: Proposed format specifier for a thousands separator

Lie Ryan lie.1296 at gmail.com
Sat Mar 14 03:08:38 CET 2009


Raymond Hettinger wrote:
> 
> 
> Motivation:
> 
>     Provide a simple, non-locale aware way to format a number
>     with a thousands separator.
> 
>     Adding thousands separators is one of the simplest ways to
>     improve the professional appearance and readability of
>     output exposed to end users.
> 
>     In the finance world, output with commas is the norm.  Finance
> users
>     and non-professional programmers find the locale approach to be
>     frustrating, arcane and non-obvious.
> 
>     It is not the goal to replace locale or to accommodate every
>     possible convention.  The goal is to make a common task easier
>     for many users.


Raymod, I think there are several problems with the Motivations:

 >     The goal is to make a common task easier
 >     for many users.

Common task, for most people, means formatting numbers to the locale. We 
should make converting numbers to locale easier to use, as easy as 
calling a magic function that can convert the current object to the 
locale representation or as simple as defining locale ID in the mini 
language. This proposal, I believe, is for the _less_ common task of 
formatting a number to a custom format not generally used anywhere else 
in the world (like formatting a number to form an ipv6 address or 
formatting a number to html/TeX code[1]).

[1] I know one mathematic textbook that uses superscript negative for 
negative number to disambiguate it with minus sign.

 >     In the finance world, output with commas is the norm.

I can't cite any source, but I am skeptical with that. And how about 
non-finance world? Scientific world? Pure math world?

 >     Provide a simple, non-locale aware way to format a number
 >     with a thousands separator.

Many have pointed out, locale is hard to use, this is easier approach 
but pity it is not locale aware. If we want to provide a non-locale 
aware formatting, we must make it flexible enough to make it the 
"Ultimate Formatter". Otherwise it will just be redundant to locale.

 >     Adding thousands separators is one of the simplest ways to
 >     improve the professional appearance and readability of
 >     output exposed to end users.

There are infinitely many approach to numbers. One Singaporean text book 
uses half-width space as thousand separator. One Autralian text book 
uses superscript minus for negative numbers (which I believe would 
require more than Unicode to represent, TeX or PDF perhaps). The 
accounting world sometimes uses colors and parentheses to denote 
negative numbers (this requires emmiting codes for the layout program: 
HTML, TeX, PDF)

Anything less powerful than my proposed "Crossing Mayan line" is just a 
harder alternative for locale module.



More information about the Python-list mailing list