Friday, February 10, 2012

Python Tip: Format number with comma

Here is a good little tip for the client that wants to see those commas in there numbers: (for python 2.6)

>>> import locale
>>> locale.setlocale(locale.LC_ALL,"")
'English_United States.1252'
>>> y = locale.format('%d',1239811,True)
>>> print y
1,239,811


Enjoy