this is mostly visible when using Postgresql since DecimalFields with a
value of 0 are saved with the decimal precision higher than 6 , ex:
0.00000000 then in the admin instead of seeing 0 or 0.00000000 it is
displayed as 0E-8
the bug can be fixed by converting the Decimal to a fixed point value in
admin/utils.py:
@@ -375,7 +375,7 @@ def display_for_field(value, field):
elif isinstance(field, (models.DateField, models.TimeField)):
return formats.localize(value)
elif isinstance(field, models.DecimalField):
- return formats.number_format(value, field.decimal_places)
+ return formats.number_format(format(value, "f"),
field.decimal_places)
elif isinstance(field, models.FloatField):
return formats.number_format(value)
else:
--
Ticket URL: <https://code.djangoproject.com/ticket/23935>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_docs: => 0
* needs_tests: => 0
* needs_better_patch: => 0
Old description:
> In the django admin, if a DecimalField's value is lower than 0.000001
> displays as Scientific Notation (ex: 1E-7) since python Decimals converts
> automatically to a scientific notation (exponential) ex:
> Decimal("0.0000001") = Decimal('1E-7')
>
> this is mostly visible when using Postgresql since DecimalFields with a
> value of 0 are saved with the decimal precision higher than 6 , ex:
> 0.00000000 then in the admin instead of seeing 0 or 0.00000000 it is
> displayed as 0E-8
>
> the bug can be fixed by converting the Decimal to a fixed point value in
> admin/utils.py:
>
> @@ -375,7 +375,7 @@ def display_for_field(value, field):
> elif isinstance(field, (models.DateField, models.TimeField)):
> return formats.localize(value)
> elif isinstance(field, models.DecimalField):
> - return formats.number_format(value, field.decimal_places)
> + return formats.number_format(format(value, "f"),
> field.decimal_places)
> elif isinstance(field, models.FloatField):
> return formats.number_format(value)
> else:
New description:
In the django admin, if a DecimalField's value is lower than 0.000001
displays as Scientific Notation (ex: 1E-7) since python Decimals converts
automatically to a scientific notation (exponential) ex:
Decimal("0.0000001") = Decimal('1E-7')
this is mostly visible when using Postgresql since DecimalFields with a
value of 0 are saved with the decimal precision higher than 6 , ex:
0.00000000 then in the admin instead of seeing 0 or 0.00000000 it is
displayed as 0E-8
the bug can be fixed by converting the Decimal to a fixed point value in
admin/utils.py:
{{{
@@ -375,7 +375,7 @@ def display_for_field(value, field):
elif isinstance(field, (models.DateField, models.TimeField)):
return formats.localize(value)
elif isinstance(field, models.DecimalField):
- return formats.number_format(value, field.decimal_places)
+ return formats.number_format(format(value, "f"),
field.decimal_places)
elif isinstance(field, models.FloatField):
return formats.number_format(value)
else:
}}}
--
--
Ticket URL: <https://code.djangoproject.com/ticket/23935#comment:1>
Old description:
> In the django admin, if a DecimalField's value is lower than 0.000001
> displays as Scientific Notation (ex: 1E-7) since python Decimals converts
> automatically to a scientific notation (exponential) ex:
> Decimal("0.0000001") = Decimal('1E-7')
>
> this is mostly visible when using Postgresql since DecimalFields with a
> value of 0 are saved with the decimal precision higher than 6 , ex:
> 0.00000000 then in the admin instead of seeing 0 or 0.00000000 it is
> displayed as 0E-8
>
> the bug can be fixed by converting the Decimal to a fixed point value in
> admin/utils.py:
>
> {{{
> @@ -375,7 +375,7 @@ def display_for_field(value, field):
> elif isinstance(field, (models.DateField, models.TimeField)):
> return formats.localize(value)
> elif isinstance(field, models.DecimalField):
> - return formats.number_format(value, field.decimal_places)
> + return formats.number_format(format(value, "f"),
> field.decimal_places)
> elif isinstance(field, models.FloatField):
> return formats.number_format(value)
> else:
> }}}
New description:
In the django admin, if a DecimalField's value is lower than 0.000001
displays as Scientific Notation (ex: 1E-7) since python Decimals converts
automatically to a scientific notation (exponential) ex:
Decimal("0.0000001") = Decimal('1E-7')
this is mostly visible when using Postgresql since DecimalFields with a
value of 0 are saved with the decimal precision higher than 6 , ex:
0.00000000 then in the admin instead of seeing 0 or 0.00000000 it is
displayed as 0E-8
the bug can be fixed by converting the Decimal to a fixed point value in
admin/utils.py:
{{{
@@ -375,7 +375,7 @@ def display_for_field(value, field):
elif isinstance(field, (models.DateField, models.TimeField)):
return formats.localize(value)
elif isinstance(field, models.DecimalField):
- return formats.number_format(value, field.decimal_places)
+ return formats.number_format(format(value, "f"),
field.decimal_places)
elif isinstance(field, models.FloatField):
return formats.number_format(value)
else:
}}}
link to my branch: https://github.com/xblitz/django/tree/ticket_23935
--
--
Ticket URL: <https://code.djangoproject.com/ticket/23935#comment:2>
* status: new => assigned
* owner: nobody => xblitz
--
Ticket URL: <https://code.djangoproject.com/ticket/23935#comment:3>
Old description:
> In the django admin, if a DecimalField's value is lower than 0.000001
> displays as Scientific Notation (ex: 1E-7) since python Decimals converts
> automatically to a scientific notation (exponential) ex:
> Decimal("0.0000001") = Decimal('1E-7')
>
> this is mostly visible when using Postgresql since DecimalFields with a
> value of 0 are saved with the decimal precision higher than 6 , ex:
> 0.00000000 then in the admin instead of seeing 0 or 0.00000000 it is
> displayed as 0E-8
>
> the bug can be fixed by converting the Decimal to a fixed point value in
> admin/utils.py:
>
> {{{
> @@ -375,7 +375,7 @@ def display_for_field(value, field):
> elif isinstance(field, (models.DateField, models.TimeField)):
> return formats.localize(value)
> elif isinstance(field, models.DecimalField):
> - return formats.number_format(value, field.decimal_places)
> + return formats.number_format(format(value, "f"),
> field.decimal_places)
> elif isinstance(field, models.FloatField):
> return formats.number_format(value)
> else:
> }}}
>
> link to my branch: https://github.com/xblitz/django/tree/ticket_23935
New description:
In the django admin, if a DecimalField's value is lower than 0.000001
displays as Scientific Notation (ex: 1E-7) since python Decimals converts
automatically to a scientific notation (exponential) ex:
Decimal("0.0000001") = Decimal('1E-7')
this is mostly visible when using Postgresql since DecimalFields with a
value of 0 are saved with the decimal precision higher than 6 , ex:
0.00000000 then in the admin instead of seeing 0 or 0.00000000 it is
displayed as 0E-8
the bug can be fixed by converting the Decimal to a fixed point value in
django.utils.numberformat.format:
link to my branch: https://github.com/xblitz/django/tree/ticket_23935
--
--
Ticket URL: <https://code.djangoproject.com/ticket/23935#comment:4>
* component: contrib.admin => Utilities
* stage: Unreviewed => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/23935#comment:5>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"9d1a69579b996eaa208f141b409141be63f597ec"]:
{{{
#!CommitTicketReference repository=""
revision="9d1a69579b996eaa208f141b409141be63f597ec"
Fixed #23935 -- Converted decimals to fixed point in
utils.numberformat.format
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23935#comment:6>
* severity: Normal => Release blocker
* cc: cmawebsite@… (added)
* version: 1.7 => 1.8alpha1
* easy: 1 => 0
* has_patch: 1 => 0
* stage: Ready for checkin => Unreviewed
Comment:
I'm using a custom "Money" subclass of DecimalField that automatically
adds a dollar sign when displaying. It works fine on 1.7 but now it
doesn't work.
Is it too late possibly change this? We could move this to a {{
value|decimalformat }} filter, or we could do {{ |stringformat:"F" }}
If the ship has already sailed, that's ok too. I can always find a
different way to do it.
--
Ticket URL: <https://code.djangoproject.com/ticket/23935#comment:7>
Comment (by collinanderson):
On 1.7 the template renders the string "$27.98", but on 1.8 its "27.98".
My Money() subclass overrides __str__/__unicode__.
--
Ticket URL: <https://code.djangoproject.com/ticket/23935#comment:8>
Comment (by timgraham):
I don't see how this low-level fix would translate to using a template
filter (e.g. in form inputs)? Nor do I understand your code well enough to
understand how this fix broke it. If you had a test or even a snippet to
demonstrate the change in behavior, that would be helpful.
--
Ticket URL: <https://code.djangoproject.com/ticket/23935#comment:9>
Comment (by collinanderson):
Ok, here's a rough failing test case demonstrating my issue:
https://github.com/django/django/pull/3921
--
Ticket URL: <https://code.djangoproject.com/ticket/23935#comment:10>