Formatting question : printing numbers with thousands separators ?
Emile van Sebille
emile at fenx.com
Fri Aug 31 08:55:33 EDT 2001
use locale:
>>> import locale
>>> locale.setlocale(locale.LC_ALL,"")
'English_United States.1252'
>>> print locale.format('%.3f',12345.6789,1)
12,345.679
But watch out for negative numbers:
>>> print locale.format('%.3f',-345.6789,1)
-,345.679
HTH,
--
Emile van Sebille
emile at fenx.com
---------
"Fred Pacquier" <fredp at mygale.org.nospam> wrote in message
news:Xns910E8A4B714EBPaCmAnRDLM at 161.48.128.20...
>
> Sorry if this is a really dumb question, but I believe I did my homework
> (docs, FATS, Google etc.) and the answer still eludes me :
>
> how do I print 246814345 as 246,814,345 (or 246 814 345) ?
>
> TIA,
> fp
>
> --
> YAFAP : http://www.multimania.com/fredp/
More information about the Python-list
mailing list