Re: [Django] #14317: numberformat.format produces wrong results

13 views
Skip to first unread message

Django

unread,
Apr 22, 2012, 6:02:13 AM4/22/12
to django-...@googlegroups.com
#14317: numberformat.format produces wrong results
-------------------------------------+-------------------------------------
Reporter: akaariai | Owner: akaariai
Type: Bug | Status: new
Component: | Version: 1.2
Internationalization | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: Localization, | Needs documentation: 1
number formatting | Patch needs improvement: 1
Has patch: 1 | UI/UX: 0
Needs tests: 1 |
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by akaariai):

* easy: 0 => 1
* stage: Design decision needed => Accepted


Comment:

I am marking this accepted as there is a definite bug:
{{{
In [1]: from django.utils.numberformat import format

In [2]: format(0.00000000000099, ',', 2)
Out[2]: u'9,9e'
}}}

An idea for solving this ticket without too much complications: large
numbers are returned in exponent format if str(number) contains 'e' in it
- this is, floats get returned in exponent format, other numbers in
decimal format. Small numbers are truncated to the decimal places
(rounding happens except for strings). So, you would get something like
this
{{{
> format('0.666', ',', 2)
OUT: 0,66
> format(0.666, ',', 2)
OUT: 0,67
> format(decimal(1e37), ',', 2)
OUT: 10000000000000000000000000000000000000,00
> format(float(1e37), ',', 2)
OUT: 1e37
> format(float(1e-37), ',', 2)
OUT: 0,00
> format(decimal(1e-37), ',', 2)
OUT: 0,00
}}}

I think the above might be straightforward to code and would get rid of
the worst inconsistencies. Comments?

If somebody wants a somewhat easy ticket to work on, I am willing to let
go of my ownership of this ticket...

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

Django

unread,
May 26, 2012, 5:53:48 PM5/26/12
to django-...@googlegroups.com
#14317: numberformat.format produces wrong results
-------------------------------------+-------------------------------------
Reporter: akaariai | Owner: anonymous
Type: Bug | Status: new
Component: | Version: 1.2
Internationalization | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: Localization, | Needs documentation: 1
number formatting | Patch needs improvement: 1
Has patch: 1 | UI/UX: 0
Needs tests: 1 |
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by anonymous):

* owner: akaariai => anonymous


Comment:

I will let go of this ticket, I currently have no time to work on this
issue.

--
Ticket URL: <https://code.djangoproject.com/ticket/14317#comment:8>

Django

unread,
Sep 7, 2012, 3:47:50 PM9/7/12
to django-...@googlegroups.com
#14317: numberformat.format produces wrong results
-------------------------------------+-------------------------------------
Reporter: akaariai | Owner: rvarshney
Type: Bug | Status: new
Component: | Version: 1.2
Internationalization | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: Localization, | Needs documentation: 1
number formatting | Patch needs improvement: 1
Has patch: 1 | UI/UX: 0
Needs tests: 1 |
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by varshney.ruchi@…):

* owner: anonymous => rvarshney


Comment:

I have created a pull request for this here. This pull request does not
treat '0.666' and 0.666 differently. i.e. they are both formatted as 0.67.
Please review and let me know.
Thanks!

https://github.com/django/django/pull/348

--
Ticket URL: <https://code.djangoproject.com/ticket/14317#comment:9>

Django

unread,
May 18, 2013, 5:56:08 AM5/18/13
to django-...@googlegroups.com
#14317: numberformat.format produces wrong results
-------------------------------------+-------------------------------------
Reporter: akaariai | Owner: anonymous
Type: Bug | Status: assigned

Component: | Version: 1.2
Internationalization | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: Localization, | Needs documentation: 1
number formatting | Patch needs improvement: 1
Has patch: 1 | UI/UX: 0
Needs tests: 1 |
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by lukenio):

* status: new => assigned
* owner: rvarshney => anonymous


--
Ticket URL: <https://code.djangoproject.com/ticket/14317#comment:10>

Django

unread,
May 18, 2013, 6:58:54 AM5/18/13
to django-...@googlegroups.com
#14317: numberformat.format produces wrong results
-------------------------------------+-------------------------------------
Reporter: akaariai | Owner: anonymous
Type: Bug | Status: assigned
Component: | Version: 1.5

Internationalization | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: Localization, | Needs documentation: 1
number formatting | Patch needs improvement: 1
Has patch: 1 | UI/UX: 0
Needs tests: 1 |
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by lukenio):

* version: 1.2 => 1.5


--
Ticket URL: <https://code.djangoproject.com/ticket/14317#comment:11>

Django

unread,
May 18, 2013, 7:52:58 AM5/18/13
to django-...@googlegroups.com
#14317: numberformat.format produces wrong results
-------------------------------------+-------------------------------------
Reporter: akaariai | Owner: lukenio

Type: Bug | Status: assigned
Component: | Version: 1.5
Internationalization | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: Localization, | Needs documentation: 1
number formatting | Patch needs improvement: 1
Has patch: 1 | UI/UX: 0
Needs tests: 1 |
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by lukenio):

* owner: anonymous => lukenio


--
Ticket URL: <https://code.djangoproject.com/ticket/14317#comment:12>

Django

unread,
May 18, 2013, 9:06:01 AM5/18/13
to django-...@googlegroups.com
#14317: numberformat.format produces wrong results
-------------------------------------+-------------------------------------
Reporter: akaariai | Owner: lukenio
Type: Bug | Status: assigned
Component: | Version: 1.5
Internationalization | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: Localization, | Needs documentation: 1
number formatting | Patch needs improvement: 1
Has patch: 1 | UI/UX: 0
Needs tests: 1 |
Easy pickings: 1 |
-------------------------------------+-------------------------------------

Comment (by apollo13):

Attached a mergeable version (including the tests) from the PR.

--
Ticket URL: <https://code.djangoproject.com/ticket/14317#comment:13>

Django

unread,
Sep 19, 2013, 8:37:50 AM9/19/13
to django-...@googlegroups.com
#14317: numberformat.format produces wrong results
-------------------------------------+-------------------------------------
Reporter: akaariai | Owner: lukenio
Type: Bug | Status: assigned
Component: | Version: 1.5
Internationalization | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: Localization, | Needs documentation: 1
number formatting | Patch needs improvement: 1
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by timo):

* needs_tests: 1 => 0
* easy: 1 => 0


Comment:

Haven't reviewed the patch in detail, but the tests contain the `u''`
prefix on some strings which is a syntax error on Python 3.2. It also no
longer applies cleanly.

--
Ticket URL: <https://code.djangoproject.com/ticket/14317#comment:14>

Django

unread,
Apr 14, 2019, 4:26:39 AM4/14/19
to django-...@googlegroups.com
#14317: numberformat.format produces wrong results
-------------------------------------+-------------------------------------
Reporter: Anssi Kääriäinen | Owner: Bartosz
| Grabski

Type: Bug | Status: assigned
Component: | Version: 1.5
Internationalization |
Severity: Normal | Resolution:
Keywords: Localization, | Triage Stage: Accepted
number formatting |
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Bartosz Grabski):

* owner: lukenio => Bartosz Grabski


--
Ticket URL: <https://code.djangoproject.com/ticket/14317#comment:15>

Django

unread,
Apr 14, 2019, 5:10:09 AM4/14/19
to django-...@googlegroups.com
#14317: numberformat.format produces wrong results
-------------------------------------+-------------------------------------
Reporter: Anssi Kääriäinen | Owner: Bartosz
| Grabski
Type: Bug | Status: assigned
Component: | Version: master

Internationalization |
Severity: Normal | Resolution:
Keywords: Localization, | Triage Stage: Accepted
number formatting |
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Bartosz Grabski):

* version: 1.5 => master


--
Ticket URL: <https://code.djangoproject.com/ticket/14317#comment:16>

Django

unread,
Aug 4, 2020, 9:40:31 PM8/4/20
to django-...@googlegroups.com
#14317: numberformat.format produces wrong results
-------------------------------------+-------------------------------------
Reporter: Anssi Kääriäinen | Owner: Bartosz
| Grabski
Type: Bug | Status: closed
Component: | Version: master
Internationalization |
Severity: Normal | Resolution: fixed

Keywords: Localization, | Triage Stage: Accepted
number formatting |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* status: assigned => closed
* needs_better_patch: 1 => 0
* resolution: => fixed
* needs_docs: 1 => 0


Comment:

Cannot reproduce the original bug report in master. I believe two commits
addressed this:

- the security patch 9cc6a60040b0f64f8ea066dd215176d4bd16621d
- the followup optimization for decimals smaller than (i.e. more digits
than) 1e-200 in 614250d90c011fffb63e6cc460aa881a206b8d53

--
Ticket URL: <https://code.djangoproject.com/ticket/14317#comment:17>

Reply all
Reply to author
Forward
0 new messages