Formatting Currency According to Locale

Discussion in 'Python' started by Daniele Varrazzo, Apr 28, 2004.

  1. 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
     
    Daniele Varrazzo, Apr 28, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Maurice Hulsman
    Replies:
    1
    Views:
    1,855
    Guus Bosman
    Jul 25, 2004
  2. Travis

    ICU Locale Currency

    Travis, Dec 5, 2007, in forum: C++
    Replies:
    0
    Views:
    271
    Travis
    Dec 5, 2007
  3. Adam Monsen
    Replies:
    0
    Views:
    374
    Adam Monsen
    Dec 19, 2007
  4. Malcolm Greene
    Replies:
    0
    Views:
    292
    Malcolm Greene
    Apr 9, 2008
  5. Michael Schuerig
    Replies:
    0
    Views:
    106
    Michael Schuerig
    May 1, 2005
Loading...

Share This Page