#34363: floatformat() crashes on "0.0000"
---------------------------------+-----------------------------------------
     Reporter:  Takis Issaris    |                    Owner:  Takis Issaris
         Type:  Bug              |                   Status:  assigned
    Component:  Template system  |                  Version:  4.2
     Severity:  Release blocker  |               Resolution:
     Keywords:  filters          |             Triage Stage:  Accepted
    Has patch:  1                |      Needs documentation:  0
  Needs tests:  0                |  Patch needs improvement:  0
Easy pickings:  0                |                    UI/UX:  0
---------------------------------+-----------------------------------------

Comment (by Takis Issaris):

 My actual code was different, but I had tried to keep the patch-size
 minimal.

 The code I was using in  a separate test-file in which I factored out the
 get_precision function for easier
 testing. But I figured this might not be OK for performance reasons for
 Django.

 {{{
 def get_precision(d: Decimal, p: int) -> int:
     """Return the number of significant digits for a decimal number.

     d: the decimal number
     p: the number of decimals requested
     """
     if d == 0:
         # If the number is zero, the precision is the number of decimals
 requested
         return p
     _, digits, exponent = d.as_tuple()
     units = len(digits)  # total number of digits
     before_comma = units + exponent

     # adding 1 for possible rounding up e.g. (99.99, 1) -> 100.0 needs 4
 digits
     prec = abs(p) + before_comma + 1
     return max(1, prec)
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34363#comment:4>
Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018678fda57c-7bae1c35-a090-49eb-8532-2bc7296b5913-000000%40eu-central-1.amazonses.com.

Reply via email to