Skip to content
Astera Technology

Why does adding 0.1 and 0.2 miss an exact 0.3 report filter?

Use the supplied integer tick basis for an exact discrete total.

Download complete case notes and answer keys ↓

Prepare the report input

The fictional source supplies canonical integer tenths beside an approximate REAL display: one and two tenths. The report asks for exactly three tenths. Binary floating-point addition need not equal the binary value of literal 0.3; compare the canonical ticks.

Every record and report rule below is original and fictional. Reproduce the setup in a fresh SQLite test database; input previews include every table in this small fixture.

Synthetic input: measures
idbatchdisplay_valuetenths
1A0.11
2A0.22
Download editable CSV ↓
Complete CREATE and INSERT fixture
CREATE TABLE measures(id INTEGER PRIMARY KEY,batch TEXT NOT NULL,display_value REAL NOT NULL,tenths INTEGER NOT NULL); INSERT INTO measures VALUES(1,'A',0.1,1),(2,'A',0.2,2);

Compare misleading and corrected results

Misleading SELECT: reproduce the defect
SELECT batch,SUM(tenths) AS tenths FROM measures GROUP BY batch HAVING SUM(display_value)=0.3 ORDER BY batch;
Literal misleading result
Query result
No rows returned (empty result)
Download editable CSV ↓
Corrected SELECT
SELECT batch,SUM(tenths) AS tenths FROM measures GROUP BY batch HAVING SUM(tenths)=3 ORDER BY batch;
Literal corrected result
batchtenths
A3
Download editable CSV ↓

The REAL equality returns no rows; integer SUM(tenths)=3 returns batch A. This fix relies on the supplied exact tick field, not arbitrary rounding of unknown measurements.

Check a fresh boundary case

A zero reading with zero ticks preserves the exact total of three.

Recreate the original setup in another fresh database, then apply the change and corrected query below. For an empty result, the table displays a labelled empty-result marker rather than a data record.

Boundary change and corrected query
INSERT INTO measures VALUES(3,'A',0.0,0);
SELECT batch,SUM(tenths) AS tenths FROM measures GROUP BY batch HAVING SUM(tenths)=3 ORDER BY batch;
Literal boundary result
batchtenths
A3
Download editable CSV ↓

What canonical total qualifies A?

Show the worked answer

1+2=3 tenths, unchanged by adding zero. Empty REAL-equality output does not prove the discrete total differed.

Related resources