{ "amount": "12.50", "currency": "CHF" } (also accepts a JSON number)
{ "amount": 1250, "currency": "CHF" } (integer minor units)
Fowler's allocation: split an amount by ratios so the parts sum exactly to the original. The remainder (at most one minor unit per part) is handed out left to right.
Human-readable message for logging / dev tooling.
Locale-aware formatting via Intl. de-CH gives "CHF 1’234.50",
bs-BA gives "1.234,50 KM", en-US gives "$1,234.50".
locale must be a valid BCP 47 tag; it comes from your own config, not
from the network, so a bad one is a programming error, not a runtime one.
Parse a decimal amount. Prefer strings from the wire; a number is accepted but anything that isn't representable exactly (0.1 + 0.2, 1e21) is rejected rather than silently rounded.
Structural guard for the rare place that receives a Money as unknown
(e.g. a schema adapter).
Scale by a factor (VAT, discount, exchange rate). The result is rounded to a
minor unit with round; Math.round is half-up toward +infinity, which is
what most invoices expect. Pass Math.floor / Math.ceil or your own for
other policies. For splitting an amount into parts use allocate, which
never loses a minor unit.
Float for display libraries only (Intl). Never do math on this.
Exact decimal string, e.g. "-1234.50". Use this for the wire and for inputs.
Exact, dependency-free Money values, arithmetic, formatting, and wire codecs.