Insert comma in number?

Peter Otten __peter__ at web.de
Thu Mar 7 09:58:24 CET 2013


Paul Volkov wrote:

> 2013/3/7 Peter Otten <__peter__ at web.de>:
>> Last not least there's the option to employ locale-aware formatting:
>>
>>>>> import locale
>>>>> locale.setlocale(locale.LC_ALL, "en_US.UTF-8")
>> 'en_US.UTF-8'
>>>>> locale.format("%d", 12345, grouping=True)
>> '12,345'
>>
>> In German usage of "." and "," is reversed, so:
>>
>>>>> locale.setlocale(locale.LC_ALL, "de_DE.UTF-8")
>> 'de_DE.UTF-8'
>>>>> locale.format("%d", 12345, grouping=True)
>> '12.345'
> 
> Does this locale-aware example only work on UNIX?

If you have Windows in mind: I don't know what it takes to get multiple 
locales on a Windows system, but for the default locale that you can specify 
with

locale.setlocale(locale.LC_ALL, "")

it should work.




More information about the Python-list mailing list