* 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.
* 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>
* 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>
* status: new => assigned
* owner: rvarshney => anonymous
--
Ticket URL: <https://code.djangoproject.com/ticket/14317#comment:10>
* version: 1.2 => 1.5
--
Ticket URL: <https://code.djangoproject.com/ticket/14317#comment:11>
* owner: anonymous => lukenio
--
Ticket URL: <https://code.djangoproject.com/ticket/14317#comment:12>
Comment (by apollo13):
Attached a mergeable version (including the tests) from the PR.
--
Ticket URL: <https://code.djangoproject.com/ticket/14317#comment:13>
* 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>
* owner: lukenio => Bartosz Grabski
--
Ticket URL: <https://code.djangoproject.com/ticket/14317#comment:15>
* version: 1.5 => master
--
Ticket URL: <https://code.djangoproject.com/ticket/14317#comment:16>
* 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>