AP® Computer Science A glossary
Round-off error
Course: AP® Computer Science A Shows up in: Unit 1: Using Objects and Methods
An error that occurs when a double result is more precise than can be stored, so the value is rounded to a representable one.
Appears in the course and exam description (CED): 1.5.C.1
A double has a limited amount of memory. Values such as 0.1 cannot be stored exactly, so small errors appear. Using int values, such as money in cents, avoids them.
System.out.println(0.1 + 0.2);
Output:
0.30000000000000004 Learn it properly, with a checkpoint 1.5 Casting and Range of Variables