← All packages

@lacspace/money

v1.0.2App & Utils Kit0 deps

Money done right — integer minor units (no floating-point cent bugs), currency-safe arithmetic, remainder-preserving allocation/split, and localized formatting via Intl. Zero-dependency, isomorphic.

npm i @lacspace/money

Usage

money.ts
import { money, Money } from "@lacspace/money";

const price = money(19.99, "USD");   // 1999 minor units, exact
price.multiply(3).format();          // "$59.97"
price.add(money(5, "USD"));          // $24.99
money(9.99, "USD").add(money(1, "EUR")); // ❌ throws: currency mismatch

// Split a bill three ways — the cent doesn't vanish
money(10, "USD").allocate([1, 1, 1]).map((m) => m.format());
// ["$3.34", "$3.33", "$3.33"]   (sum is exactly $10.00)

// Zero-decimal & 3-decimal currencies handled automatically
money(1000, "JPY").format("ja-JP"); // "¥1,000"
money(1.5, "BHD").toMinor();        // 1500  (BHD has 3 decimals)

Exports 4

MoneydecimalsFormoneysumMoney

Keywords

moneycurrencydinero-alternativeminor-unitscentsdecimal

More in App & Utils Kit