Rebasely Beta: data may be purged

examples/storefront Public

Markdown · 837 B · at 48ffd57

id: 0003-money-in-whole-cents
type: decision
owner: justin
status: accepted
reviewed: 2026-10-01

0003 Money is whole cents

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 currency column on products and carts, and totals per currency.