#23935 closed Bug (fixed)
DecimalField in admin can show up as Scientific Notation
Reported by: | Eric | Owned by: | Eric |
---|---|---|---|
Component: | Utilities | Version: | 1.8alpha1 |
Severity: | Release blocker | Keywords: | DecimalField admin |
Cc: | cmawebsite@… | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
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
Change History (10)
comment:1 by , 10 years ago
Description: | modified (diff) |
---|
comment:2 by , 10 years ago
Description: | modified (diff) |
---|
comment:3 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 10 years ago
Description: | modified (diff) |
---|
comment:5 by , 10 years ago
Component: | contrib.admin → Utilities |
---|---|
Triage Stage: | Unreviewed → Ready for checkin |
comment:6 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
comment:7 by , 10 years ago
Cc: | added |
---|---|
Easy pickings: | unset |
Has patch: | unset |
Severity: | Normal → Release blocker |
Triage Stage: | Ready for checkin → Unreviewed |
Version: | 1.7 → 1.8alpha1 |
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.
comment:8 by , 10 years ago
On 1.7 the template renders the string "$27.98", but on 1.8 it's "27.98".
My Money() subclass overrides str/unicode.
comment:9 by , 10 years ago
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.
comment:10 by , 10 years ago
Ok, here's a rough failing test case demonstrating my issue:
https://github.com/django/django/pull/3921
In 9d1a69579b996eaa208f141b409141be63f597ec: