Money/decimal values rounded wrongly: FLOAT precision and DECIMAL scale mistakes
Sums of FLOAT/REAL values drift (0.1 + 0.2 != 0.3), or a DECIMAL column rounds values you inserted.
floating point rounding error SQL0.1 + 0.2 not equal 0.3 SQLDECIMAL rounds my valuemoney stored as FLOATSUM of float is not exact Meaning
Never store money in FLOAT/DOUBLE. Use DECIMAL(p, s)/NUMERIC with enough scale, round deliberately (ROUND), and be aware that inserting more decimals than the scale rounds silently (or errors in strict mode).
Common causes
- FLOAT/DOUBLE used for currency
- DECIMAL scale too small (e.g. 10,2 for rates)
- Implicit casts through float in the ORM
- Rounding before summing
- Different rounding modes (half-even vs half-up)
⚡ Quick fix
- Use
DECIMAL(19, 4)or integer minor units for money - Round only at presentation or defined steps
- Avoid float math in the application layer
Detailed fix by platform
SQL
- sql
ALTER TABLE invoices ALTER COLUMN total TYPE numeric(19,4); SELECT ROUND(SUM(total), 2) FROM invoices;
How to diagnose
- Type — FLOAT or DECIMAL?
- Scale — Enough?
- Rounding — Where?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in SQL
Other ways to find it
Where this error sits
Origin: Data. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 18 Nov 2026