[Django]-DecimalField Converts Zero to 0E-10

20πŸ‘

βœ…

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

πŸ‘€xblitz

Leave a comment