Insert comma in number?

Paul Volkov capt-obvious at yandex.ru
Thu Mar 7 03:30:35 EST 2013


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?



More information about the Python-list mailing list