{{{
>>> from django.utils.numberformat import format as nformat
>>> nformat(Decimal('1e-199'), '.', decimal_pos=2)
'0.00'
>>> nformat(Decimal('1e-200'), '.', decimal_pos=2)
'1.00e-200'
}}}
This is caused by a hardcoded cut-off point in the internal logic, but I
would argue that when a `decimal_pos` argument is supplied and the number
to be formatted is smaller in absolute size than what can be encoded using
the provided number of decimal positions, the returned string should be
`0.0000...000` instead.
--
Ticket URL: <https://code.djangoproject.com/ticket/30363>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* type: Uncategorized => Cleanup/optimization
* stage: Unreviewed => Accepted
Comment:
Hi Sjoerd.
OK, so this is related to the changes in
9cc6a60040b0f64f8ea066dd215176d4bd16621d.
Happy to Accept as a **potential** Cleanup/optimization — I guess
ultimately it depends on what the change looks like. (i.e. is the nicer
behaviour worth the extra complexity? etc)
I'm assuming you're ready/willing to make the patch...?
Thanks!
--
Ticket URL: <https://code.djangoproject.com/ticket/30363#comment:1>
Comment (by Sjoerd Job Postmus):
Yes, definitely willing to pick it up as a patch. It should be a fairly
minimal addition.
--
Ticket URL: <https://code.djangoproject.com/ticket/30363#comment:2>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/30363#comment:3>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"e6d57c4d652f16ac8f8d4600c0b7c30fcfcde6c2" e6d57c4d]:
{{{
#!CommitTicketReference repository=""
revision="e6d57c4d652f16ac8f8d4600c0b7c30fcfcde6c2"
Fixed #30363 -- Do not use exponential notation for small decimal numbers.
In 9cc6a60040b0f64f8ea066dd215176d4bd16621d a security patch was
introduced to prevent allocating large segments of memory when a
very large or very small decimal number was to be formatted.
As a side-effect, there was a change in formatting of small decimal
numbers even when the `decimal_pos` argument was provided, which meant
that reasonable small decimal numbers (above 1e-199) would be formatted
as `0.00`, while smaller decimal numbers (under 1e-200) would be
formatted as `1e-200`.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30363#comment:4>
Comment (by Florian Apolloner <apollo13@…>):
In [changeset:"e6d57c4d652f16ac8f8d4600c0b7c30fcfcde6c2" e6d57c4d]:
{{{
#!CommitTicketReference repository=""
revision="e6d57c4d652f16ac8f8d4600c0b7c30fcfcde6c2"
Fixed #30363 -- Do not use exponential notation for small decimal numbers.
In 9cc6a60040b0f64f8ea066dd215176d4bd16621d a security patch was
introduced to prevent allocating large segments of memory when a
very large or very small decimal number was to be formatted.
As a side-effect, there was a change in formatting of small decimal
numbers even when the `decimal_pos` argument was provided, which meant
that reasonable small decimal numbers (above 1e-199) would be formatted
as `0.00`, while smaller decimal numbers (under 1e-200) would be
formatted as `1e-200`.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30363#comment:5>