Django 1.6, Python 2.7.5+, PostgreSQL 9.1, Linux.
I have several decimal fields defined in the model like this:
min_inclusive = models.DecimalField(_('minimum inclusive'), max_digits=19,
decimal_places=10,
help_text=_("Enter the minimum (inclusive) value for this concept."),
null=True, blank=True)
Via the admin interface when I enter a 0
(zero) and save the object I get 0E-10
as the value.
So, why doesn't it just store and display a zero?
The documentation doesn't specify if decimal_places
is forced or if it is a maximum number.
Is this display because 10 places are required? If so, the using the default form widget, TextInput
, it seems to me that is should just expand to that size or at least scroll to that size.
In PostgreSQL it is stored as 0.0000000000
So if you insert 0 in an SQLite number field and then select it, you will get 0 . But if you insert 0 in a PostgreSQL numeric field it will do a zero fill on the decimal and insert 0.0000000000 . So when Python puts this in a Decimal you will see Decimal("0E-10") .
1 - decimal value 0.00000000 converted to scientific notation 0E-8.
I have also ran into this problem and found out that actually everything is working right. In Python if you actually define something like this Decimal("0.0000000000")
you will see this in the console:
>>> Decimal("0.0000000000")
Decimal('0E-10')
In my situation I was converting from SQLite3 backend to PostgreSQL for production. Everything was working fine in SQLite, because it doesn't explicitly show (or store) all decimal digits. So if you insert 0
in an SQLite number field and then select it, you will get 0
.
But if you insert 0
in a PostgreSQL numeric field it will do a zero fill on the decimal and insert 0.0000000000
. So when Python puts this in a Decimal you will see Decimal("0E-10")
.
UPDATE - fixed in Django 1.8
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With