{{{
>>> format(0.0000000000000000009, '.', 2)
'9e-19.00'
>>> format(1e16, '.', 2, thousand_sep=',', grouping=3,
force_grouping=True)
'1e,+16.00'
}}}
This is similar to #23935 but that was only fixed for Decimal types.
--
Ticket URL: <https://code.djangoproject.com/ticket/28280>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* component: Uncategorized => Utilities
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted
Old description:
> For floats with values larger than 1e16 or smaller than 1e-5, their
> string representation uses scientific notation in Python, which causes
> {{{numberformat.format}}} to return an erroneous output.
>
> {{{
> >>> format(0.0000000000000000009, '.', 2)
> '9e-19.00'
> >>> format(1e16, '.', 2, thousand_sep=',', grouping=3,
> force_grouping=True)
> '1e,+16.00'
> }}}
>
> This is similar to #23935 but that was only fixed for Decimal types.
New description:
For floats with values larger than 1e16 or smaller than 1e-5, their string
representation uses scientific notation in Python, which causes
{{{numberformat.format}}} to return an erroneous output.
{{{
>>> from django.utils.numberformat import format
>>> format(0.0000000000000000009, '.', 2)
'9e-19.00'
>>> format(1e16, '.', 2, thousand_sep=',', grouping=3,
force_grouping=True)
'1e,+16.00'
}}}
This is similar to #23935 but that was only fixed for Decimal types.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/28280#comment:1>
* needs_better_patch: 0 => 1
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/8612 PR] (with a few comments for
improvement)
--
Ticket URL: <https://code.djangoproject.com/ticket/28280#comment:2>
Comment (by Tim Graham <timograham@…>):
In [changeset:"b94d99af5b6692476ad1722682eedbe076985654" b94d99af]:
{{{
#!CommitTicketReference repository=""
revision="b94d99af5b6692476ad1722682eedbe076985654"
Refs #28280 -- Added more tests for utils.numberformat.format().
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28280#comment:3>
* owner: nobody => Hasan Ramezani
* needs_better_patch: 1 => 0
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/28280#comment:4>
* needs_better_patch: 0 => 1
* version: 1.11 => master
--
Ticket URL: <https://code.djangoproject.com/ticket/28280#comment:5>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/28280#comment:6>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/28280#comment:7>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"bc1c03407649a37a8a3c26b8d0cb355ab2fc128e" bc1c0340]:
{{{
#!CommitTicketReference repository=""
revision="bc1c03407649a37a8a3c26b8d0cb355ab2fc128e"
Fixed #28280 -- Prevented numberformat.format() from formatting large/tiny
floats in scientific notation.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28280#comment:8>