Formatting question : printing numbers with thousands separators ?

Joonas Paalasmaa joonas at olen.to
Fri Aug 31 09:01:37 EDT 2001


Fred Pacquier wrote:
> 
> 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) ?

If that number has fixed number of characters you can use slicing

>>> stringvalue = str(246814345)
>>> stringvalue[0:3]+","+stringvalue[3:6]+","+stringvalue[6:9]
'246,814,345'
>>>



More information about the Python-list mailing list