Any prices, totals, or financial math — where floating-point cents bugs and currency mix-ups are unacceptable.
Overview
0.1 + 0.2 !== 0.3 — so never store money as a float. Keeps amounts as integer minor units, refuses to add different currencies, splits a bill without losing a cent (allocate), handles zero- and three-decimal currencies, and formats with Intl. Immutable, typed.
Store and compute in integer minor units; only format for display with `.format(locale)`.
Split bills with `.allocate([ratios])` / `.split(n)` — the remainder is distributed so the total is always exact.
Zero-decimal (JPY) and three-decimal (BHD/KWD) currencies are handled automatically.
Zero-dependency and isomorphic — safe to import on the server, in the browser, on the edge and in React Native. It tree-shakes, so you only ship what you import.
Watch out for
Arithmetic across different currencies throws — convert first with your own FX rate.
`.toMajor()` returns a JS number for convenience; prefer `.format()` for display to avoid float rounding.
Looking for the complete API and more examples? The npm page and GitHub README carry the full reference — or grab the PDF.