Python: format currency 

Joined:
04/09/2007
Posts:
703

May 15, 2010 19:53:27    Last update: May 15, 2010 19:54:37
Use the locale module.
>>> a = 1234.5678
>>> import locale
>>> locale.setlocale(locale.LC_ALL, '')  # set default locale
'English_United States.1252'
>>> locale.currency(a)
'$1234.57'
>>> locale.currency(a, grouping=True)
'$1,234.57'
>>>
Share |
| Comment  | Tags
 
Easy email testing with http://www.ximailstop.com