Browse guides

Represent money with the Valyrian.js utilities

Carry one amount from localized input through arithmetic to currency display.

The example converts `19.90` into cents, adds five dollars and renders the localized `24.90 USD` total.

Table of contents

Main APIs

Money
Represents a monetary amount in integer cents and provides arithmetic operations.
NumberFormatter
Builds and transforms a numeric value before locale-aware formatting.
formatMoney
Formats a Money or numeric value with the requested currency and locale options.
parseMoneyInput
Parses a localized text value into a Money amount.
MoneyFormatOptions
Type. Locale and number-format options for formatMoney.
v-money
Concept. Formats money input and stores minor units.
ts
import { mount } from "valyrian.js";
import { Money, formatMoney, parseMoneyInput } from "valyrian.js/money";

const subtotal = parseMoneyInput("19.90", { decimalPlaces: 2 });
const total = subtotal.add(Money.fromCents(500));

mount("body", () => formatMoney(total, { currency: "USD", locale: "en-US" }));

Error

Formatting returns a localized representation and does not change the `Money` amount.

Exact references