DECIMAL SQL Origin: Data OSI layer 7 · Application Last updated 18 Nov 2026

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.

Exact message you may see floating point rounding error SQL0.1 + 0.2 not equal 0.3 SQLDECIMAL rounds my valuemoney stored as FLOATSUM of float is not exact
Seen on: SQL MySQL PostgreSQL

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

  1. Use DECIMAL(19, 4) or integer minor units for money
  2. Round only at presentation or defined steps
  3. Avoid float math in the application layer

Detailed fix by platform

SQL

  1. sql
    ALTER TABLE invoices ALTER COLUMN total TYPE numeric(19,4);
    SELECT ROUND(SUM(total), 2) FROM invoices;

How to diagnose

  1. Type — FLOAT or DECIMAL?
  2. Scale — Enough?
  3. 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:

Where this error sits

Origin: Data. Errors that are often confused with or caused by this one (click to open):

= NULL — WHERE col = NULL returns no rows (use IS NULL) (SQL)= NULL22003 — ERROR: numeric field overflow — A field with precision 5, scale 2 must round to an absolute value less than 10^3 (PostgreSQL)220038115 — SQL Server: Arithmetic overflow error converting expression to data type int. (Msg 8115) (SQL)8115cartesian — Query returns far too many rows: accidental Cartesian product (missing JOIN condition) (SQL)cartesianCASE — CASE expression returns mixed types: conversion failed / types cannot be matched (SQL)CASECOUNT — COUNT(column) ignores NULLs: counts differ from COUNT(*) (SQL)COUNTdate format — Dates mixed up: dd/mm/yyyy vs mm/dd/yyyy, ISO 8601 recommended (SQL)date formatinteger division — 5 / 2 = 2: integer division silently truncates the result (SQL)integer divisionDECIMAL

Explore the map of this error Full error map →

🧠 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.