Computer Science

Integer Division Truncation Mistake

Students divide two integers and expect a decimal result, but the language cuts off the fractional part.

Quick check

Why students make it

Students think division always works like calculator division. They miss that the operand types can decide whether the operation uses integer division or floating-point division.

The rule done right

In languages such as Java, C, C++, and C#, dividing two integers uses integer division, so the fractional part is discarded. To keep the fraction, make at least one operand floating-point before dividing.