Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Formatting Currency According to Locale

Reply
Thread Tools

Formatting Currency According to Locale

 
 
Daniele Varrazzo
Guest
Posts: n/a
 
      04-28-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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Parsing locale specific dates, currency, numbers Malcolm Greene Python 0 04-09-2008 05:50 PM
formatting issues displaying currency other than locale's default Adam Monsen Java 0 12-19-2007 12:30 AM
ICU Locale Currency Travis C++ 0 12-05-2007 04:34 PM
Formatting and parsing dates according to locale? Michael Schuerig Ruby 0 05-01-2005 01:21 PM
i18n problem, involving Locale.getDisplayLanguage and Locale.getDisplayCountry Maurice Hulsman Java 1 07-25-2004 06:11 PM



Advertisments