The ISO currency code (e.g. "ANG").
The numeric amount to format.
Upper bound on decimal places (default 2). Raise it
for small per-unit prices so $0.0042 doesn't collapse to $0.00.
The symbol-prefixed amount, e.g. "€18.00".
formatWithSymbol("USD", 19.99); // => "$19.99"
formatWithSymbol("ANG", 43.5); // => "ƒ43.50"
formatWithSymbol("USD", 0.0042, 4); // => "$0.0042"
export function formatWithSymbol(
currency: string,
amount: number,
maximumFractionDigits = 2,
): string {
const symbol = CURRENCY_SYMBOL_MAP[currency] ?? currency;
const formatted = new Intl.NumberFormat(undefined, {
minimumFractionDigits: 2,
maximumFractionDigits,
}).format(amount);
return `${symbol}${formatted}`;
}
Formats an amount with its currency symbol (from CURRENCY_SYMBOL_MAP), e.g.
"ƒ43.50". Uses the symbol map rather thanIntl'scurrencystyle so currencies whoseIntlsymbol is their code (e.g. ANG → "ANG") still render the proper glyph (ANG → "ƒ"), matching the drawer's price-range adornment. The number is grouped/decimal-formatted in the runtime locale; falls back to the raw code when no symbol is known.