I feel stoopid ... this code is to verbose

Jeff Epler jepler at unpythonic.net
Fri Jun 14 14:15:54 EDT 2002


On Fri, Jun 14, 2002 at 06:19:29PM +0200, Max M wrote:
> Hmm ... I am working on a problem. In Danish we have a number format 
> that looks like:
> 
> 42.000.000,00 which is 42 millions

See the 'locale' module, functions 'format' and (internal) _group.
If you can call locale.setlocale() to one which requires these
separators, it should take care of the rest on calls to .format().

>>> locale.setlocale(locale.LC_ALL, "da_DK")
'da_DK'
>>> locale.format("%.2f", 42000000.0, 1)
'42.000.000,00'

Jeff





More information about the Python-list mailing list