Skip to content
GreenSnippets

Format currency and numbers with Intl

Locale-aware money, percent and compact number formatting using the built-in Intl.NumberFormat.

JavaScript
function formatMoney(amountMinor, currency = "USD", locale = "en-US") {
  return new Intl.NumberFormat(locale, { style: "currency", currency }).format(amountMinor / 100);
}

const formatPercent = (ratio, locale = "en-US") =>
  new Intl.NumberFormat(locale, { style: "percent", maximumFractionDigits: 1 }).format(ratio);

const formatCompact = (n, locale = "en-US") =>
  new Intl.NumberFormat(locale, { notation: "compact" }).format(n);

Example / expected output

Output
formatMoney(123456)                 // "$1,234.56"
formatMoney(123456, "EUR", "de-DE") // "1.234,56 €"
formatPercent(0.256)                // "25.6%"
formatCompact(1_250_000)            // "1.3M"

How it works

Never build currency strings by hand: symbols, separators and placement differ per locale. Store money as integer minor units (cents) and divide only for display. In hot paths, create the formatter once and reuse it.