#15789: floatformat filter works incorrectly when decimal precision is set low
--------------------------------------+-------------------------------
               Reporter:  akaihola    |        Owner:  nobody
                   Type:  Bug         |       Status:  new
              Milestone:              |    Component:  Template system
                Version:  SVN         |     Severity:  Normal
             Resolution:              |     Keywords:
           Triage Stage:  Unreviewed  |    Has patch:  0
    Needs documentation:  0           |  Needs tests:  0
Patch needs improvement:  0           |
--------------------------------------+-------------------------------
Changes (by akaihola):

 * needs_better_patch:   => 0
 * needs_tests:   => 0
 * needs_docs:   => 0


Comment:

 What happens inside `floatformat` when evaluating
 `decimal.getcontext().prec = 2 ; floatformat(1.23456789123, 2)` is
 equivalent to this:
 {{{
 >>> import decimal
 >>> decimal.getcontext().prec = 2
 >>> d = decimal.Decimal('1.23456789123')
 >>> exp = decimal.Decimal('0.01')
 >>> d.quantize(exp, decimal.ROUND_HALF_UP)
 Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "/usr/lib/python2.6/decimal.py", line 2358, in quantize
     'quantize result has too many digits for current context')
   File "/usr/lib/python2.6/decimal.py", line 3778, in _raise_error
     raise error(explanation)
 decimal.InvalidOperation: quantize result has too many digits for current
 context
 }}}

 At this point, `floatformat` eats the exception and just returns the
 original value without truncating the decimal part.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/15789#comment:1>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

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

Reply via email to