Can Python format long integer 123456789 to 12,3456,789 ?

D H no at spam.please
Thu Jun 1 23:16:38 EDT 2006


A.M wrote:
> Hi,
> 
> Is there any built in feature in Python that can format long integer 
> 123456789 to 12,3456,789 ?

Apparently you need to use the locale module.  This is the
example they give online to print a simple number with commas:

import locale
locale.setlocale(locale.LC_ALL, 'English_United States.1252')
print locale.format("%d", 123456789, grouping=True)

Someone should make a module that uses .NET or Java's formmating.
You just use {0:n} or ###,### instead of all the above.
http://blog.stevex.net/index.php/string-formatting-in-csharp/
http://java.sun.com/docs/books/tutorial/i18n/format/decimalFormat.html



More information about the Python-list mailing list