Perhaps I should clarify why I posted this to -developers: If the
answer to my previous post is "no, it's not possible to globally
configure the decimal module", then I think it would make sense to
alter format_number() to check for a setting which determines the
rounding used for the quantize() call. settings.DECIMAL_ROUNDING or
something like that would be my suggestion. I'd be happy to supply a
patch if people think this sounds reasonable.

On Dec 21, 2:52 am, 3point2 <[email protected]> wrote:
> Hello,
>
> I just tracked down what I thought was a bug in my invoicing
> application to the default rounding used by python's decimal module.
> The default, decimal.ROUND_HALF_EVEN will round 1.25 to 1.2 rather
> than 1.3 for DecimalFields before putting them in the DB. This happens
> in django.db.backends.util.format_number. I want to use
> decimal.ROUND_HALF_UP, which is actually used by the floatformat
> template filter at django.template.defaultfilters.floatformat.
>
> My question: Is there any way to change the behavior of the decimal
> module as currently called by django.db.backends.util.format_number so
> that i can get the behavior I want without patching Django to pass the
> setting to the quantize() call? I looked though the documentation for
> the decimal module and tried
>
> decimal.getcontext().rounding = decimal.ROUND_HALF_UP
>
> in my settings.py, but that didn't make a difference.
>
> Thanks for any comments/suggestions,
>
> Vasili

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to