currency template tag problems

Create issue
Issue #1196 resolved
Former user created an issue

Hi, === first problem === in file:

line 121 in function moneyfmt, there is {{{ #!python formatted = u"%s<%s>%s</%s>" % formatted[:pos], wrapcents, formatted[pos:], wrapcents }}}

should be {{{ #!python formatted = u"%s<%s>%s</%s>" % (formatted[:pos], wrapcents, formatted[pos:], wrapcents) }}}

otherwise doesn't work for me when parameter wrapcents=sup to templatetag currency is used

=== second problem === the currency templatetag according to doc, supports optional argument: places

however the before mentioned function moneyfmt does not. it's signature

def moneyfmt(val, currency_code=None, wrapcents=''):

should be changed to def moneyfmt(val, currency_code=None, wrapcents='', places=2):

and param handled correctly

Comments (3)

  1. Chris Moffitt repo owner

    Thanks for the report. In e3d46f3c8b80 I committed the first fix.

    Regarding your second issue, it is an issue but the fix is a little more challenging. The way to specify decimal places is to use the l10_settings as shown here:

    l10n_settings_defaults = {
        # (or global settings) -- all other defaults should be added using
        # the add_setting_defaults method !
        'currency_formats' : {
            'USD' : {'symbol': u'$', 'positive' : u"$%(val)0.2f", 'negative': u"-$%(val)0.2f", 'decimal' : '.'},
            'GBP' : {'symbol': u'£', 'positive' : u%(val)0.2f", 'negative': u"-£%(val)0.2f", 'decimal' : '.'},

    In this case if you wanted to change your decimal settings, you could modify the formatting expression in your settings.

    However, this wouldn't work if there were some places you wanted to show 2 decimal places and some places 3.

    The other challenge is how do you handle a situation where someone wants to do this:

    'EURO' : {'symbol': u'€', 'positive' : u"€%(val)0.2f", 'negative': u"€(%(val)0.2f)", 'decimal' : ','},

    The use of the parenthesis in the negative situation makes it difficult to figure out the best way to solve this scenario. I'm leaving open for now to track the discussion.

  2. Vladimir Linhart

    Nice fix! I was thinking about similar solution.

    I know it's an unprobable situation but the regex would be safer in case the formating string is like this: u"€%(val)0.12f" it would fail. fix would be.

    decimal_fmt = re.compile(r'(\.\d+f)')


  3. Log in to comment