Why shouldn't I store money as FLOAT in a database?
0.1 isn't exact in binary, so sums drift and cents go missing. Use DECIMAL or integer minor units, store the currency, and make rounding an explicit business rule.
In this article
- 01Why floats can't hold money
- 02Option 1: fixed-point DECIMAL / NUMERIC
- 03Option 2: integers in minor units
- 04Things to avoid
· 6 min read
