cross platform use of set locale

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Tue Mar 22 19:53:20 EST 2005


In <mailman.751.1111537997.1799.python-list at python.org>, Timothy Smith
wrote:
>>> hi there i need to set my locale so that when i output a number it's
>>> formatted with thousands grouped. […]
>>
>>  import locale
>>  locale
>>  locale.setlocale(LC_ALL, '')
>>  locale.format('%.2f', 1000000, True)
>>
>>The `True` turns on grouping.  Should work cross platform.
>
> thats ok, but how do i get it to group thousands with a , ? and thats
> would mean i'd have to run everything through a formatter before i
> displayed it :/ it'd be nicer if i could just select a proper locale

It uses the locale of the system.  If *your* systems locale is configured
to use ',' as separator for grouping, then it should be used by
`locale.format()`.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list