Truncation

In AP Computer Science A, truncation is when Java drops the decimal portion of a number without rounding, which happens automatically during integer division (7/2 evaluates to 3, not 3.5) and when casting a double to an int ((int) 3.9 becomes 3).

Verified for the 2027 AP Computer Science A examLast updated June 2026

What is Truncation?

Truncation means cutting off the fractional part of a number and keeping only the whole-number part. No rounding happens. Java doesn't ask whether the decimal is closer to the next number up or down; it just throws the decimal away. So (int) 9.99 becomes 9, and (int) -4.7 becomes -4 (truncation moves toward zero, not down).

In AP CSA you run into truncation in two main places. First, integer division: when both operands are int, the / operator performs integer division and truncates the result, so 7 / 2 is 3 and 5 / 10 is 0. Second, casting: writing (int) in front of a double forces Java to truncate it. This is one of the most common sources of "my math is wrong" bugs on the exam and in real code, because the expression looks like normal arithmetic but quietly loses information.

Why Truncation matters in AP Computer Science A

Truncation lives in Unit 1 (Primitive Types), where the CED covers arithmetic expressions with int and double and casting between them. The exam expects you to evaluate expressions exactly the way Java does, and that means knowing that int / int truncates. A huge number of multiple-choice questions hinge on this single fact. If a question asks what (int)(temp * 100) / 100.0 does, you need to recognize the truncate-then-divide pattern used to round or chop decimals to a fixed number of places.

Truncation also explains why the order of operations and operand types matter so much. 5 / 2 * 2.0 is 4.0, not 5.0, because the truncation happens before the double ever enters the picture. The College Board loves expressions like this because they test whether you actually trace code or just do mental math.

How Truncation connects across the course

Modulo Operator (Unit 1)

Integer division and modulo are two halves of one operation. Division truncates and gives you the quotient (7/2 is 3), while % gives you the leftover that truncation threw away (7%2 is 1). Together they let you split a number into digits or convert units, a pattern that shows up constantly in FRQ-style method writing.

Casting between int and double (Unit 1)

A cast like (int) 3.9 truncates to 3, full stop. The classic exam trick is rounding a positive double by writing (int)(x + 0.5), which uses truncation to fake rounding. Know that truncation goes toward zero, so (int) -3.9 is -3, not -4.

Substring (Unit 2)

Truncation has a string cousin. Calling str.substring(0, n) chops off everything after index n, which is conceptually the same move as truncating a number's decimal places. Both are about discarding the tail end of data, which matches the general definition of truncation.

Is Truncation on the AP Computer Science A exam?

Truncation shows up most heavily in Unit 1 multiple-choice questions that ask you to evaluate an arithmetic expression. Watch for stems like "What is the value of the expression 13 / 4 + 13 % 4?" where the whole question is testing whether you truncate at the right moment. It also appears in code-tracing questions where an int variable stores the result of a division, silently losing the decimal.

On FRQs, truncation matters when you write methods involving averages, percentages, or splitting numbers. If you compute an average with sum / count where both are int, you'll truncate and likely lose a point. The fix is to make one operand a double, like (double) sum / count. Knowing when truncation happens (and how to prevent it) is a scoring skill, not just a definition.

Truncation vs Rounding

Rounding picks the nearest whole number; truncation just deletes the decimal. So 3.9 rounds to 4 but truncates to 3. Java's (int) cast and integer division always truncate, never round. If a problem needs actual rounding of a positive double, the standard trick is (int)(x + 0.5), which adds half before truncating so the chop lands on the right number.

Key things to remember about Truncation

  • Truncation removes the decimal part of a number without rounding, so 7.99 truncates to 7.

  • In Java, dividing two ints always truncates, which is why 7 / 2 evaluates to 3 and 5 / 10 evaluates to 0.

  • Casting a double to an int, like (int) 4.6, truncates to 4; it never rounds up.

  • Truncation moves toward zero, so (int) -4.7 becomes -4, not -5.

  • Integer division and modulo are partners: the / operator gives the truncated quotient and % gives the remainder that was thrown away.

  • To avoid unwanted truncation in an average, cast one operand to double first, as in (double) sum / count.

Frequently asked questions about Truncation

What is truncation in AP Computer Science A?

Truncation is when Java drops the decimal portion of a number without rounding. It happens automatically in integer division (7 / 2 equals 3) and when casting a double to an int ((int) 3.9 equals 3).

Does Java round when you divide two ints?

No. Integer division truncates, it never rounds. 9 / 2 is 4, not 4.5 and not 5. The decimal is simply discarded. If you want a decimal result, make at least one operand a double.

What's the difference between truncation and rounding?

Rounding goes to the nearest whole number, truncation just cuts the decimal off. 6.8 rounds to 7 but truncates to 6. Java's (int) cast and / with two ints always truncate, so you have to use the (int)(x + 0.5) trick if you actually want rounding.

What does (int) -4.7 evaluate to in Java?

It evaluates to -4. Truncation moves toward zero rather than rounding down, so the .7 is dropped and the value gets less negative. This is a favorite gotcha on multiple-choice questions.

Why does 5 / 10 equal 0 in Java?

Because both operands are ints, Java performs integer division and truncates the true answer of 0.5 down to 0. Writing 5.0 / 10 or 5 / 10.0 makes one operand a double, so the result is 0.5.