5 / 2 = 2: integer division silently truncates the result
Dividing two integers returns an integer in most databases, so decimals are dropped.
integer division returns 05 / 2 returns 2SQL division result truncatedpercentage always 0 integer divisiondivide returns integer not decimal Meaning
In PostgreSQL, SQL Server, SQLite and Oracle (via NUMBER rules differ) 5 / 2 gives 2. Cast one operand (5 / 2.0, 5::numeric / 2, CAST(x AS DECIMAL)) before dividing, especially for percentages and averages.
Common causes
- Both operands are integers
- Percentage computed as
count / total - Average of integer columns
- Casting the result instead of the operand
- Dialect differences (MySQL returns decimal)
⚡ Quick fix
- Cast one operand to DECIMAL/NUMERIC/FLOAT
- Multiply by 1.0 before dividing
- Test with edge values
Detailed fix by platform
SQL
SELECT 5 / 2 AS wrong, 5 / 2.0 AS right_, CAST(5 AS decimal(10,2)) / 2 AS also_right;
How to diagnose
- Operands — Integers?
- Cast — On operand?
- Dialect — MySQL vs others?
🔧 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