Pretty Integers
Bjorn Pettersen
BPettersen at NAREX.com
Fri Mar 15 14:23:03 EST 2002
> From: Lindstrom Greg - glinds [mailto:Greg.Lindstrom at acxiom.com]
>
> I would like to add commas to the integers I am writing (for
> example: 12345678 --> 12,345,678). I have a fairly ugly
> method that relies heavily upon mods, but am convinced there
> must be a "pretty" way to do it. How would you go about this task?
>
> Thanks, everyone!
How about:
>>> import locale
>>> locale.setlocale(locale.LC_ALL, '')
'English_United States.1252'
>>> locale.format('%d', 12345678, 3)
'12,345,678'
>>>
-- bjorn
More information about the Python-list
mailing list