locale, format monetary values

deelan ggg at zzz.it
Mon Apr 17 08:25:54 EDT 2006


Rares Vernica wrote:
> Hi,
> 
> Can I use locale to format monetary values? If yes, how? If no, is there 
> something I can use?
> 
> E.g.,
> I have 10000 and I want to get "$10,000".

try something like:

 >>> import locale
 >>> locale.setlocale(locale.LC_ALL, "en-US")
'English_United States.1252'
 >>> locale.format("%f", 10000, True)
'10,000.000000'
 >>> locale.format("$%.2f", 10000, True)
'$10,000.00'

bye.

-- 
deelan
http://www.deelan.com/
http://blog.deelan.com/



More information about the Python-list mailing list