#23935: DecimalField in admin can show up as Scientific Notation
------------------------------------+--------------------------------------
Reporter: xblitz | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.7
Severity: Normal | Resolution:
Keywords: DecimalField admin | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
------------------------------------+--------------------------------------
Changes (by xblitz):
* 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>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.91cd2adeeabd703a7e9cb98c4b2d4ec5%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.