By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,985 Members | 1,574 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,985 IT Pros & Developers. It's quick & easy.

Formatting Currency According to Locale

P: n/a
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" % (

locale.format('%.*f', (lc['frac_digits'],cash), 1))

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?


Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.