Formatting Currency According to Locale

Daniele Varrazzo piro at officine.it
Wed Apr 28 12:46:46 EDT 2004


Hi everybody

Is there any way to make the most of locale.localeconv() in formatting currencies?

I can use many tricks as
>>> locale.setlocale(locale.LC_ALL, locale.getlocale())
>>> lc = locale.localeconv()
>>>
>>> cash = 1427.48
>>> print "%s%s" % (
	lc['currency_symbol'],
	locale.format('%.*f', (lc['frac_digits'],cash), 1))
€1.427,48

But that presumes many things, such as 
lc['mon_grouping'] == lc['grouping'] # format uses the latter value, doesn't he?
lc['p_sign_posn'] == 3 # else i must change the format string, 
	# maybe building a mapping to order the pieces, splitting + and - cases...

I'm using...
Python 2.3.2 (#49, Oct 24 2003, 13:37:57) [MSC v.1200 32 bit (Intel)] on win32
... and watching localeconv(), i also see many other not much documented details: 
n_cs_precedes, n_sep_by_space... 

Is it up to me to write a function to keep all these details into account?

Bye

Daniele





More information about the Python-list mailing list