Paul D. Kraus wrote: > How can i print a float as a currency with commas. > > 1222333.4 -> 1,222,333.40 > > if i '%0.2f'%number > > i get > 1222333.40
Use locale.format():
In [1]: import locale
In [2]: f=1222333.4
In [6]: locale.setlocale(locale.LC_ALL, "")
Out[6]: 'English_United States.1252'
In [7]: locale.format('%.2f', f, True)
Out[7]: '1,222,333.40'
Kent
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor
