Skip to content

.tip

· one of the small things

Send money as an integer and a currency code

A field like "price": 19.99 is a binary float the moment anything parses it, and the cent that goes missing turns up in a total nobody can reconcile. Send a whole number of the currency's smallest unit, with the code beside it, and keep it an integer through the database and every sum.

{ "amount_minor": 1999, "currency": "USD" }

Divide only where you format, and don't hardcode 100: JPY has no minor unit, KWD has three digits. An Intl.NumberFormat built with that currency reports the exponent as resolvedOptions().maximumFractionDigits.

api-designschema-design