Login

Note to myself

2008-07-09 16:42

How to display numbers and monetary value in a locale aware way

>>> import locale
>>> locale.setlocale(locale.LC_ALL, '')
>>> locale.currency(6512.345)
'6512,35 \xe2\x82\xac'
>>> print locale.currency(6512.345)
6512,35 €
>>> print locale.currency(6512.345, grouping=True)
6.512,35 €
>>> print locale.currency(6512.345, grouping=True, international=True)
6.512,35 EUR
>>> locale.format('%#2.3f', 6512.345, True, False)
'6.512,345'

More info in the python documentation for the locale module

No comment

Post a comment