AP® Computer Science A glossary
Truncation
Also called: truncate
Course: AP® Computer Science A Shows up in: Unit 1: Using Objects and Methods
Cutting off the digits to the right of the decimal point, as (int) does when it casts a double to an int.
Appears in the course and exam description (CED): 1.5.A.2
Truncation does not round. (int) 9.99 is 9. To round a non-negative value, use (int) (x + 0.5); for a negative value, (int) (x - 0.5).
System.out.println((int) 9.99);
System.out.println((int) -3.86);
System.out.println((int) (9.99 + 0.5));
Output:
9
-3
10 Learn it properly, with a checkpoint 1.5 Casting and Range of Variables