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.
Related resources
-
Binary, Decimal, Hexadecimal Infographic -
Computer Science, Place values in a binary nibble from left to right Infographic - Programming Fundamentals Cheat Sheet
- Java Syntax Quick Reference Cheat Sheet
- AP Computer Science A Java Reference Cheat Sheet
- Place values in a binary nibble from left to right Memory Aid Cheat Sheet
- Boolean Logic & Binary Cheat Sheet
- Computer Science, Binary and Data Representation Worksheet
- Computer Science, Place Values in a Binary Nibble from Left to Right Practice Worksheet
- Computer Science, Spreadsheet Formulas to Model Real Problems Worksheet
- CS, Functions and Parameters Worksheet
- Debugging & Unit Testing Explorer Tool
- Binary, Decimal & Hex Converter Tool
- Bug Hunt, Debugging for Kids Tool
- Number Systems & Data Representation Lab Lab
- Selection & Iteration Code Tracing Lab Lab
- Selection & Iteration Lab Lab
- Debugging & Unit Testing Lab Lab