# Money/decimal values rounded wrongly: FLOAT precision and DECIMAL scale mistakes

**Code:** `DECIMAL` · **Category:** SQL · **Seen on:** SQL, MySQL, PostgreSQL

Sums of FLOAT/REAL values drift (0.1 + 0.2 != 0.3), or a DECIMAL column rounds values you inserted.

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/sql/decimal-rounding-precision-loss)
