howto format currency string?
Alex Martelli
aleax at aleax.it
Fri Aug 29 08:09:40 EDT 2003
adegreiff wrote:
> hi,
>
> using zope/pythons/page templates i need to format a float number to a
> string like 10,250.10
>
> (note the thousand separator and the trailing zero in the decimal)
>
> i was able to use %0.2f bit that returned no thousand separator.
> i was able to use thousands_commas function but that returned
> "10,250.1" which is wrong.
>
> any ideas?
>>> import locale
>>> locale.setlocale(locale.LC_ALL,('en','ascii'))
'en_US.ISO8859-1'
>>> locale.format('%.2f', 10250.10, True)
'10,250.10'
>>>
Alex
More information about the Python-list
mailing list