Testing decimal results with round()
Floats can be slightly inexact (0.1 + 0.2 is not 0.3), so round the actual result to a set number of decimal places before comparing it with the expected value.
Understanding Testing decimal results with round() in ACARA Digital Technologies Years 9–10
What it does: round(..., 2) matches the 2 decimal places of money, so tiny float errors cannot cause a false FAIL. 0.1 + 0.2 is stored as 0.30000000000000004, so a direct == comparison with 0.3 fails. round(0.30000000000000004, 2) gives 0.3, which equals the expected value. round() accepts any number of places. Pick the number that suits the problem, such as 2 for dollars and cents. Round only the actual result, then compare it using ==. Putting == inside round() rounds a True/False value. Rounding is needed for float results, which can be slightly inexact. Whole-number ints are exact. The first result has a tiny float error. The second is exact, so it passes either way.
Common mistakes: The test is meant to check 0.1 + 0.2 against 0.3. Multiplying gives 0.02, so the check would fail for the wrong reason. It should be act = 0.1 + 0.2. A single = is assignment, not comparison, so this is a syntax error. Use == to compare: ok = round(total, 2) == 25.0.
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 591–622) and word search (Modules 536–622).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
round(actual, 2) == expectedFill in the Blanks
Spot the Error
Student with a class code? Join your class →