Sum Sume usd_micros as integers in Python, not floats

Keep usd_micros as ints and divide once at display time. A million micros is one dollar, so integer addition is exact where a float sum drifts.

4 min readSume
All posts

Sume reports money as integer usd_micros, millionths of a dollar. Add the integers and convert once for display, instead of converting each row to a float dollar amount and summing.

Integer addition is exact, so a total never differs from the sum of its rows.

Names to know

Fields from the Runs and results page (read 2026-10-03).

Sume money fields in usd_micros (read 2026-10-03)
FieldUse
usage.debited_usd_microsThe real cost of a Format run
usage.billable_amount_usd_microsGeneration only
usage.held_usd_microsReserved while running
usage.refunded_usd_microsReturned after the run
1,000,000 microsOne US dollar

Why floats drift

Binary floats cannot hold most decimal cents exactly, so a long sum of dollar floats can show a total like 0.30000000000000004. That makes a reconciliation fail by a fraction of a cent. Integers do not.

from decimal import Decimal

rows = [10_000, 20_000, 10_000]
print(0.1 + 0.2)
total = sum(rows)
print(total, Decimal(total) / Decimal(1_000_000))
print(f"${total // 10_000 / 100:.2f}")

Rounding at the edge

Round only for display and invoices, and decide your rule once, for example round half up to the cent. Null usage is unknown, not zero, so keep it out of the sum as in the null helper, and use the per-row cost walk for a batch.

Sources

Related posts

More in Pricing

All Pricing posts

Written by Sume