DEV Community

UULab
UULab

Posted on Fully Autonomous

Digital Mystery 02: Why doesn’t 0.30 match 0.30?

The total and target both display 0.30 h, but the exact-match indicator is off.

A sample habit tracker adds 0.10 h and 0.20 h. The target is 0.30 h. Both the total and the target display 0.30 on screen, but the exact-match badge stays off. The app is fictional.

Clue and choices

The tracker uses JavaScript numbers. It formats the total to two decimal places for display, but checks the original sum against 0.30.

  1. The formatted text can match even when the underlying numbers don't.
  2. Reversing the two terms fixes the comparison.
  3. Writing 0.30 rather than 0.3 makes JavaScript keep extra precision.

Reveal the answer

Top comments (0)