Overeager decimal point replacement…

Issue #1082 resolved
Mikkel Høgh
created an issue

I’m making a Danish Satchmo store, and I'm struggling a bit with the moneyfmt() output…

In Denmark, the usual currency symbol is “kr.”, and usually appears after the number.

The problem is that the currency formatter replaces all periods, not just the decimal sign: {{{

!python

formatted = formatted.replace('.', sep) }}}

May I suggest this be replaced with a regular expression like this:

{{{

!python

import re

decimal_separator = re.compile(r'(\d+).(\d+)') formatted = decimal_separator.sub(r'\1%s\2' % sep, formatted)

}}}

Comments (7)

  1. Chris Moffitt repo owner

    Interesting point. This seems like a reasonable request and a valid solution. If you wouldn't mind send the patch, I'll take a look at applying and making sure there aren't any side effects lurking out there.

  2. Chris Moffitt repo owner

    In looking at the docs for replace, it seems you can add a count for number to replace. If we changed to:

    formatted = formatted.replace('.', sep,1)
    
    

    Does that work for you? Might be a simpler fix.

  3. Mikkel Høgh reporter

    That would work fine for my case, but some people put the kr. in front of the amount, in which case it would break… I don’t know if its too much of an edge case to bother with, though :)

  4. Log in to comment