Issue #1341 open

l10n.utils.moneyfmt rounding errors

David Hobbs
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. Log in to comment