How to format a number?

Clodoaldo clodoaldo.pinto at
Tue Jan 2 14:52:28 EST 2007

I want to format a number with thousands separator to the 'pt_br'

I'm trying like this:

>>> import locale
>>> locale.setlocale(locale.LC_ALL, ('pt_br', 'ascii'))
>>> locale.format('%d', 9876, True)
>>> locale.localeconv()['thousands_sep']
>>> locale.localeconv()['mon_thousands_sep']

The thousands separator is defined only for the ['mon_thousands_sep']
key and not for the ['thousands_sep'] one. What should be done? Set the
['thousands_sep'] to '.' or somehow build the format string as a
monetary number? If any of the former, how?

Regards, Clodoaldo Pinto Neto

More information about the Python-list mailing list