---
title: "Round-Off Error — AP CSA Definition & Exam Guide"
description: "Round-off error is the precision loss when a double can't be stored exactly in memory, so it gets rounded. Why 0.1 * 3 != 0.3 on the AP CSA exam."
canonical: "https://fiveable.me/ap-comp-sci-a/key-terms/round-off-error"
type: "key-term"
subject: "AP Computer Science A"
unit: "Unit 1"
---

# Round-Off Error — AP CSA Definition & Exam Guide

## Definition

In AP Computer Science A, a round-off error occurs when an expression evaluates to a double more precise than the memory allotted for the type can store, so the result is rounded to the nearest representable value (EK 1.5.C.1). It's why 0.1 * 3 does not equal 0.3 in Java.

## What It Is

A round-off error is what happens when Java can't store a decimal value exactly. Every [data type](/ap-comp-sci-a/key-terms/data-type "fv-autolink") gets a fixed amount of memory, and a `double` only has so many bits to work with. If an [expression](/ap-comp-sci-a/key-terms/expression "fv-autolink") evaluates to a value more precise than those bits can hold, Java rounds it to the nearest value it *can* represent. The number you get back is extremely close to the right answer, but not exactly the right answer.

The classic example shows up constantly in practice questions: `0.1 * 3` does not equal `0.3` in Java. Both values get stored as approximations, and the approximations don't quite match. The CED's official advice (EK 1.5.C.1) is blunt about the fix. To avoid [rounding](/ap-comp-sci-a/unit-1/casting-and-ranges-of-variables/study-guide/kW3XXEIwJwVRXFx3ntdC "fv-autolink") errors that naturally occur, use `int` values instead. That's why money calculations in well-written Java code use cents as an `int` (435 cents) rather than dollars as a `double` (4.35). Fancier decimal types exist in Java, but they're explicitly excluded from the AP exam.

## Why It Matters

Round-off error lives in Topic 1.5 (Casting and Ranges of Variables) in [Unit 1](/ap-comp-sci-a/unit-1 "fv-autolink") and directly supports learning objective [AP Comp Sci A](/ap-comp-sci-a "fv-autolink") 1.5.C, which asks you to describe conditions that limit the accuracy of expressions. It's one of two ways finite memory bites you in this topic. Doubles lose precision (round-off error), and ints run out of range (integer overflow). Together they make the same big point: computers don't store math, they store bits, and bits have limits. This idea quietly follows you through the whole course. Any time you compare doubles with `==` in a boolean expression or accumulate doubles in a loop, round-off error is lurking, and the exam loves to check whether you know it.

## Connections

### Integer overflow (Unit 1)

Round-off error's sibling in Topic 1.5. Both come from finite memory, but they fail differently. A [double](/ap-comp-sci-a/unit-1/expressions-and-assignment-statements/study-guide/01dr6uUPDAn3SjtK2Psr "fv-autolink") that's too precise gets rounded to something close to correct, while an int outside the Integer.MIN_VALUE to Integer.MAX_VALUE range overflows to a value that can be wildly wrong.

### [Cast to int (Unit 1)](/ap-comp-sci-a/key-terms/cast-to-int)

Casting a double to an int truncates everything after the decimal point (EK 1.5.A.2), which is deliberate chopping, not accidental rounding. The two interact in the rounding trick (int)(x + 0.5), where you use [truncation](/ap-comp-sci-a/key-terms/truncation "fv-autolink") on purpose to round a non-negative double to the nearest integer.

### [Arithmetic expression (Unit 1)](/ap-comp-sci-a/key-terms/arithmetic-expression)

Round-off error is born inside [arithmetic expressions](/ap-comp-sci-a/key-terms/arithmetic-expression "fv-autolink"). Each operation on doubles can introduce a tiny imprecision, and those tiny errors stack. Adding 0.1 to a total ten times in a loop does not give you exactly 1.0, even though the math says it should.

### Boolean expressions and == comparison (Unit 1)

The practical payoff. Because of round-off error, comparing doubles with == is unreliable, so correct code checks whether two doubles are close instead, like Math.abs(a - b) < 0.001. Recognizing that pattern as an 'epsilon comparison' is a common multiple-choice ask.

## On the AP Exam

Round-off error is multiple-choice territory, and the questions follow a few predictable patterns. The most common stem shows two doubles that look mathematically equal, like `0.1 * 3` and `0.3`, compared with `==`, and asks what prints. The answer is almost always "Not Equal" because of round-off error. A second pattern accumulates a double in a loop (adding 0.1 ten times) and asks whether the total equals 1.0. It doesn't. A third pattern shows a method like `Math.abs(a - b) < 0.001` and asks you to identify its purpose, which is safely comparing doubles despite round-off error. You may also see code that does money math in integer cents and be asked why, and the answer is that int arithmetic avoids the rounding errors doubles naturally produce. The skill being tested is recognizing when a computed double is an approximation, not trusting it to be exact.

## round-off error vs Integer overflow

Both are accuracy problems caused by finite memory, but they hit different types in different ways. Round-off error affects doubles, happens when a value is too *precise* to store, and produces a result very close to the true value. Integer overflow affects ints, happens when a value is too *large or small* for the 4-byte range, and produces a result that can be completely wrong (even flipping sign). One nudges your answer; the other breaks it.

## Key Takeaways

- A round-off error happens when a double is more precise than its allotted memory can store, so Java rounds it to the nearest representable value (EK 1.5.C.1).
- Because of round-off error, expressions like 0.1 * 3 == 0.3 evaluate to false in Java even though the math says they're equal.
- Never compare doubles with ==; instead check whether their difference is tiny, like Math.abs(a - b) < 0.001.
- The CED's recommended fix is to use int values when exactness matters, which is why money is often calculated in cents as an int.
- Round-off error rounds doubles to something close to correct, while integer overflow wraps ints to something potentially very wrong; don't mix them up.
- Errors accumulate: adding 0.1 to a double ten times in a loop does not produce exactly 1.0.

## FAQs

### What is a round-off error in AP Computer Science A?

It's the loss of precision that occurs when an expression evaluates to a double more exact than the type's allotted memory can store, so the result gets rounded to the nearest representable value. It's covered in Topic 1.5 under learning objective AP Comp Sci A 1.5.C.

### Why does 0.1 * 3 not equal 0.3 in Java?

Doubles are stored as binary approximations, and 0.1 can't be represented exactly in binary. The tiny errors in 0.1 * 3 and 0.3 don't match, so comparing them with == prints "Not Equal." This exact setup is a classic AP CSA multiple-choice question.

### Is round-off error the same as truncation when casting to int?

No. Round-off error is unintentional rounding caused by limited double precision, while casting a double to an int deliberately truncates (chops off) everything after the decimal point per EK 1.5.A.2. Truncation always rounds toward zero; round-off error rounds to the nearest representable value.

### How do you avoid round-off errors on the AP CSA exam?

Two ways: use int values when you need exact answers (like tracking money in cents), and compare doubles with a tolerance such as Math.abs(a - b) < 0.001 instead of ==. The CED explicitly says other special decimal data types are out of scope.

### Is round-off error the same as integer overflow?

No. Round-off error affects doubles and produces a value very close to correct, while integer overflow happens when an int expression exceeds the range Integer.MIN_VALUE to Integer.MAX_VALUE and produces a value that's in range but not necessarily correct. They're tested side by side in Topic 1.5.

## Related Study Guides

- [1.5 Casting and Ranges of Variables](/ap-comp-sci-a/unit-1/casting-and-ranges-of-variables/study-guide/kW3XXEIwJwVRXFx3ntdC)

## Structured Data

```json
{"@context":"https://schema.org","@graph":[{"@type":"LearningResource","@id":"https://fiveable.me/ap-comp-sci-a/key-terms/round-off-error#resource","name":"Round-Off Error — AP CSA Definition & Exam Guide","url":"https://fiveable.me/ap-comp-sci-a/key-terms/round-off-error","learningResourceType":"Concept explainer","educationalLevel":"AP® / High School","about":{"@id":"https://fiveable.me/ap-comp-sci-a/key-terms/round-off-error#term"},"audience":{"@type":"EducationalAudience","educationalRole":"student"},"dateModified":"2026-06-11T05:27:18.718Z","isPartOf":{"@type":"Collection","name":"AP Computer Science A Key Terms","url":"https://fiveable.me/ap-comp-sci-a/key-terms"},"publisher":{"@type":"Organization","name":"Fiveable","url":"https://fiveable.me"}},{"@type":"DefinedTerm","@id":"https://fiveable.me/ap-comp-sci-a/key-terms/round-off-error#term","name":"round-off error","description":"In AP Computer Science A, a round-off error occurs when an expression evaluates to a double more precise than the memory allotted for the type can store, so the result is rounded to the nearest representable value (EK 1.5.C.1). It's why 0.1 * 3 does not equal 0.3 in Java.","url":"https://fiveable.me/ap-comp-sci-a/key-terms/round-off-error","inDefinedTermSet":{"@type":"DefinedTermSet","name":"AP Computer Science A Key Terms","url":"https://fiveable.me/ap-comp-sci-a/key-terms"}},{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"What is a round-off error in AP Computer Science A?","acceptedAnswer":{"@type":"Answer","text":"It's the loss of precision that occurs when an expression evaluates to a double more exact than the type's allotted memory can store, so the result gets rounded to the nearest representable value. It's covered in Topic 1.5 under learning objective AP Comp Sci A 1.5.C."}},{"@type":"Question","name":"Why does 0.1 * 3 not equal 0.3 in Java?","acceptedAnswer":{"@type":"Answer","text":"Doubles are stored as binary approximations, and 0.1 can't be represented exactly in binary. The tiny errors in 0.1 * 3 and 0.3 don't match, so comparing them with == prints \"Not Equal.\" This exact setup is a classic AP CSA multiple-choice question."}},{"@type":"Question","name":"Is round-off error the same as truncation when casting to int?","acceptedAnswer":{"@type":"Answer","text":"No. Round-off error is unintentional rounding caused by limited double precision, while casting a double to an int deliberately truncates (chops off) everything after the decimal point per EK 1.5.A.2. Truncation always rounds toward zero; round-off error rounds to the nearest representable value."}},{"@type":"Question","name":"How do you avoid round-off errors on the AP CSA exam?","acceptedAnswer":{"@type":"Answer","text":"Two ways: use int values when you need exact answers (like tracking money in cents), and compare doubles with a tolerance such as Math.abs(a - b) < 0.001 instead of ==. The CED explicitly says other special decimal data types are out of scope."}},{"@type":"Question","name":"Is round-off error the same as integer overflow?","acceptedAnswer":{"@type":"Answer","text":"No. Round-off error affects doubles and produces a value very close to correct, while integer overflow happens when an int expression exceeds the range Integer.MIN_VALUE to Integer.MAX_VALUE and produces a value that's in range but not necessarily correct. They're tested side by side in Topic 1.5."}}]},{"@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"AP Computer Science A","item":"https://fiveable.me/ap-comp-sci-a"},{"@type":"ListItem","position":2,"name":"Key Terms","item":"https://fiveable.me/ap-comp-sci-a/key-terms"},{"@type":"ListItem","position":3,"name":"Unit 1","item":"https://fiveable.me/ap-comp-sci-a/unit-1"},{"@type":"ListItem","position":4,"name":"round-off error"}]}]}
```
