Mongoengine: Causeless DecimalField behavior

Created on 7 May 2014  Â·  6Comments  Â·  Source: MongoEngine/mongoengine

DecimalField should not use float to store its values. It is crucial to never use float for Decimal as it is often used for financial tasks.

I suggest to use Int and precision metainfo somewhere nearby.

DecimalField

Most helpful comment

decimal
As far as now it completely loses precision I would suggest raising NotImplementedException in order to prevent data loss.

All 6 comments

DecimalField was a contributed field - I'm more than happy to take a PR to improve it

FWIW, a new Decimal type was added in MongoDB 3.3.8 / pyMongo 3.4.

Nov 29, 2016: Newly released Mongo DB 3.4 adds decimal data type. It would make sense to use it when using Mongo DB 3.4.

@lafrech any plans for implementing this native NumberDecimal type?

I highly suggest to add big warning to docs about Decimal - Float conversion.

decimal
As far as now it completely loses precision I would suggest raising NotImplementedException in order to prevent data loss.

Explanation merged into master

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ZEROF picture ZEROF  Â·  4Comments

dmitry-saritasa picture dmitry-saritasa  Â·  4Comments

ajdas-code picture ajdas-code  Â·  4Comments

kushalmitruka picture kushalmitruka  Â·  5Comments

BenCoDev picture BenCoDev  Â·  5Comments