[Django] #28280: numberformat.format does not handle scientific notation correctly

66 views
Skip to first unread message

Django

unread,
Jun 7, 2017, 5:16:08 AM6/7/17
to django-...@googlegroups.com
#28280: numberformat.format does not handle scientific notation correctly
-----------------------------------------+------------------------
Reporter: Wil Tan | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.11
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/28280>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 7, 2017, 9:21:16 AM6/7/17
to django-...@googlegroups.com
#28280: numberformat.format does not handle scientific notation correctly
---------------------------+------------------------------------

Reporter: Wil Tan | Owner: nobody
Type: Bug | Status: new
Component: Utilities | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------+------------------------------------
Changes (by Tim Graham):

* 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>

Django

unread,
Jun 7, 2017, 10:05:44 AM6/7/17
to django-...@googlegroups.com
#28280: numberformat.format() incorrectly formats large/tiny floats in scientific
notation
---------------------------+------------------------------------

Reporter: Wil Tan | Owner: nobody
Type: Bug | Status: new
Component: Utilities | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
---------------------------+------------------------------------
Changes (by Tim Graham):

* 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>

Django

unread,
Jun 29, 2017, 1:39:26 PM6/29/17
to django-...@googlegroups.com
#28280: numberformat.format() incorrectly formats large/tiny floats in scientific
notation
---------------------------+------------------------------------
Reporter: Wil Tan | Owner: nobody
Type: Bug | Status: new
Component: Utilities | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
---------------------------+------------------------------------

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>

Django

unread,
Feb 23, 2020, 10:40:03 AM2/23/20
to django-...@googlegroups.com
#28280: numberformat.format() incorrectly formats large/tiny floats in scientific
notation
---------------------------+------------------------------------------
Reporter: Wil Tan | Owner: Hasan Ramezani
Type: Bug | Status: assigned

Component: Utilities | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------+------------------------------------------
Changes (by Hasan Ramezani):

* owner: nobody => Hasan Ramezani
* needs_better_patch: 1 => 0
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/28280#comment:4>

Django

unread,
Feb 25, 2020, 8:25:02 AM2/25/20
to django-...@googlegroups.com
#28280: numberformat.format() incorrectly formats large/tiny floats in scientific
notation
---------------------------+------------------------------------------
Reporter: Wil Tan | Owner: Hasan Ramezani
Type: Bug | Status: assigned
Component: Utilities | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
---------------------------+------------------------------------------
Changes (by felixxm):

* needs_better_patch: 0 => 1

* version: 1.11 => master


--
Ticket URL: <https://code.djangoproject.com/ticket/28280#comment:5>

Django

unread,
Feb 25, 2020, 9:08:52 AM2/25/20
to django-...@googlegroups.com
#28280: numberformat.format() incorrectly formats large/tiny floats in scientific
notation
---------------------------+------------------------------------------
Reporter: Wil Tan | Owner: Hasan Ramezani
Type: Bug | Status: assigned
Component: Utilities | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------+------------------------------------------
Changes (by Hasan Ramezani):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/28280#comment:6>

Django

unread,
Feb 26, 2020, 8:41:08 AM2/26/20
to django-...@googlegroups.com
#28280: numberformat.format() incorrectly formats large/tiny floats in scientific
notation
---------------------------+---------------------------------------------

Reporter: Wil Tan | Owner: Hasan Ramezani
Type: Bug | Status: assigned
Component: Utilities | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------+---------------------------------------------
Changes (by felixxm):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/28280#comment:7>

Django

unread,
Feb 26, 2020, 10:22:26 AM2/26/20
to django-...@googlegroups.com
#28280: numberformat.format() incorrectly formats large/tiny floats in scientific
notation
---------------------------+---------------------------------------------
Reporter: Wil Tan | Owner: Hasan Ramezani
Type: Bug | Status: closed
Component: Utilities | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------+---------------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* 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>

Reply all
Reply to author
Forward
0 new messages