Formatting question : printing numbers with thousands separators ?
aleax at aleax.it
Fri Aug 31 16:47:33 CEST 2001
"Skip Montanaro" <skip at pobox.com> wrote in message
news:mailman.999263627.3276.python-list at python.org...
> Fred> how do I print 246814345 as 246,814,345 (or 246 814 345) ?
> I'm sure there are more clever ways, but this seems to work:
Sorry for "hijacking" your response skip, but I didn't get
Fred's original question! So -- the locale module is the
one that serves this need:
>>> locale.setlocale(locale.LC_NUMERIC, 'us')
Unfortunately, this implies a global, non-thread-safe
change, and is NOT oriented to just letting one format
a number once with a given thousand-separator, so it
may or may not be what one was looking for.
More information about the Python-list