Decision 0003 Accepted
- Owner
- justin
- Reviewed
- 2026-10-01
Context
Prices, line totals, shipping and order totals are added and compared in SQL and in TypeScript. Floating point dollars round differently in each place, and payment providers take integer amounts anyway.
Decision
Every amount is an integer number of cents, in columns and fields named *_cents, in one currency (usd, CURRENCY in src/money.ts). Input that is not a whole number of cents is refused, not rounded. Formatting for people happens only at the edge, with formatCents.
Consequences
- Totals add up the same in D1, in the Worker and at the payment provider.
- A second currency is a schema change: a
currencycolumn on products and carts, and totals per currency.