- Resources & Library
- For Developers & Technical Teams
- Backend & Databases
Use DECIMAL for Financial Values
FLOAT and DOUBLE cannot represent many decimal fractions exactly, and tiny differences can become reconciliation and calculation errors.
Omar Alalwi Article
FLOAT and DOUBLE are designed for fast approximate computation and store numbers in binary form. Many common decimal fractions therefore have no exact representation, which can introduce small differences during addition, comparison, or rounding.
For prices, balances, and taxes, use DECIMAL with precision and scale chosen for the domain. In application code, avoid converting the value to a floating-point type before calculating or storing it; use a dependable decimal type or integer minor units when the business rules support that approach.
Numeric precision is only one part of financial correctness. Define where and how rounding happens, keep currencies explicit, record movements instead of relying only on a balance, and test fractional, aggregation, and reversal cases. The decision must remain consistent from the database to the user interface.
Share your perspective
I’d be glad to hear your perspective. Leave a comment on the original article on social media.