Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#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 Eric)

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 Eric, 10 years ago

Description: modified (diff)

comment:2 by Eric, 10 years ago

Description: modified (diff)

comment:3 by Eric, 10 years ago

Owner: changed from nobody to Eric
Status: newassigned

comment:4 by Eric, 10 years ago

Description: modified (diff)

comment:5 by Tim Graham, 10 years ago

Component: contrib.adminUtilities
Triage Stage: UnreviewedReady for checkin

comment:6 by Tim Graham <timograham@…>, 10 years ago

Resolution: fixed
Status: assignedclosed

In 9d1a69579b996eaa208f141b409141be63f597ec:

Fixed #23935 -- Converted decimals to fixed point in utils.numberformat.format

comment:7 by Collin Anderson, 10 years ago

Cc: cmawebsite@… added
Easy pickings: unset
Has patch: unset
Severity: NormalRelease blocker
Triage Stage: Ready for checkinUnreviewed
Version: 1.71.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 Collin Anderson, 10 years ago

On 1.7 the template renders the string "$27.98", but on 1.8 its "27.98".

My Money() subclass overrides str/unicode.

Version 0, edited 10 years ago by Collin Anderson (next)

comment:9 by Tim Graham, 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 Collin Anderson, 10 years ago

Ok, here's a rough failing test case demonstrating my issue:
https://github.com/django/django/pull/3921

Note: See TracTickets for help on using tickets.
Back to Top