l10n.utils.moneyfmt rounding errors

Create issue
Issue #1341 open
Former user created an issue

I noticed that the same number would round in one direction on Windows and the other on Linux. It turns out the moneyfmt function uses the string format operator to round a float (using for example, {{{u"$%(val)0.2f"}}}) rather than Decimal.quantize.

A fix is simple: {{{ --- a/satchmo/apps/l10n/utils.py Wed Aug 03 09:54:16 2011 -0700 +++ b/satchmo/apps/l10n/utils.py Wed Aug 03 23:32:03 2011 -0400 @@ -1,1 +1,1 @@ -from decimal import Decimal +from decimal import Decimal, ROUND_HALF_UP @@ -129,1 +129,1 @@ - + @@ -140,1 +140,1 @@ - formatted = fmt % { 'val' : val } + formatted = fmt % {'val' : val.quantize(Decimal('0.01'), ROUND_HALF_UP)} }}}

Comments (5)

  1. Former user Account Deleted

    Never mind my "fix" -- I realized it doesn't accommodate a variable number of rounding places.

  2. Former user Account Deleted

    I'm attaching a patch that accounts for variable rounding places.

    I forgot to update one of the comments, so I re-added the attachment.

  3. Log in to comment