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

5 / 2 = 2: integer division silently truncates the result

Dividing two integers returns an integer in most databases, so decimals are dropped.

Exact message you may see integer division returns 05 / 2 returns 2SQL division result truncatedpercentage always 0 integer divisiondivide returns integer not decimal
Seen on: SQL PostgreSQL SQL Server SQLite

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

  1. Cast one operand to DECIMAL/NUMERIC/FLOAT
  2. Multiply by 1.0 before dividing
  3. Test with edge values

Detailed fix by platform

SQL

  1. SELECT 5 / 2 AS wrong, 5 / 2.0 AS right_, CAST(5 AS decimal(10,2)) / 2 AS also_right;

How to diagnose

  1. Operands — Integers?
  2. Cast — On operand?
  3. 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:

Where this error sits

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

8134 — SQL Server Msg 8134: Divide by zero error encountered (SQL)8134Array to string conversion — Warning: Array to string conversion (PHP)Array to string conve…AttributeError — AttributeError: 'X' object has no attribute 'y' (Python)AttributeErrorCannot use object as array — Fatal error: Uncaught Error: Cannot use object of type stdClass as array (PHP)Cannot use object as …cartesian — 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)CASEClassCastException — java.lang.ClassCastException: class A cannot be cast to class B (Java)ClassCastExceptionCOUNT — COUNT(column) ignores NULLs: counts differ from COUNT(*) (SQL)COUNTinteger d…

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.