Formatting question : printing numbers with thousands separators ?
fredp at mygale.org.nospam
Fri Aug 31 16:47:20 CEST 2001
gerson.kurz at t-online.de (Gerson Kurz) said :
> On 31 Aug 2001 11:33:52 GMT, Fred Pacquier <fredp at mygale.org.nospam>
>>how do I print 246814345 as 246,814,345 (or 246 814 345) ?
> def f(x):
> s,i = list(str(x)),3
> while i < len(s):
> i += 4
> return ''.join(s)
Well, before rolling my own buggy routine I wanted to check I wasn't
overlooking something ready-made "à la sprintf". Turns out I wasn't looking
in the right place -- as thousands separators are country-dependent, the
"locale" module is the way to go...
YAFAP : http://www.multimania.com/fredp/
More information about the Python-list