Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deal with rounding errors of floating types for financial calculations in Python SQLite? [duplicate]

I'm creating a financial app and it seems my floats in sqlite are floating around. Sometimes a 4.0 will be a 4.000009, and a 6.0 will be a 6.00006, things like that. How can I make these more exact and not affect my financial calculations?

Values are coming from Python if that matters. Not sure which area the messed up numbers are coming from.

like image 275
Recursion Avatar asked Dec 03 '22 14:12

Recursion


1 Answers

Please use Decimal

http://docs.python.org/library/decimal.html

like image 68
YOU Avatar answered Dec 28 '22 23:12

YOU