Formatting Currency with Intl.NumberFormat in JavaScript

Learn how to use JavaScript's Intl.NumberFormat API to format currency values correctly for any locale. Covers options, edge cases, and best practices for web applications.

Development

Detailed Explanation

Intl.NumberFormat for Currency

The Intl.NumberFormat API is the standard way to format numbers as currency in JavaScript. It handles locale-specific formatting rules including symbol placement, thousands separators, decimal separators, and grouping automatically.

Basic Usage

// US Dollar in English
new Intl.NumberFormat("en-US", {
  style: "currency",
  currency: "USD",
}).format(1234.56);
// => "$1,234.56"

// Japanese Yen (0 decimals)
new Intl.NumberFormat("ja-JP", {
  style: "currency",
  currency: "JPY",
}).format(1234);
// => "¥1,234"

// Euro in German (comma as decimal separator)
new Intl.NumberFormat("de-DE", {
  style: "currency",
  currency: "EUR",
}).format(1234.56);
// => "1.234,56 €"

Key Options

Option Values Description
style "currency" Required for currency formatting
currency ISO 4217 code Required — "USD", "EUR", etc.
currencyDisplay "symbol", "narrowSymbol", "code", "name" How to show the currency
minimumFractionDigits 0–20 Minimum decimal places
maximumFractionDigits 0–20 Maximum decimal places
signDisplay "auto", "never", "always", "exceptZero" When to show +/- signs

Narrow vs. Wide Symbols

// "symbol" (default) — may use CA$ for disambiguation
new Intl.NumberFormat("en-US", {
  style: "currency",
  currency: "CAD",
  currencyDisplay: "symbol",
}).format(100);
// => "CA$100.00"

// "narrowSymbol" — always uses $
new Intl.NumberFormat("en-US", {
  style: "currency",
  currency: "CAD",
  currencyDisplay: "narrowSymbol",
}).format(100);
// => "$100.00"

Edge Cases

  • Negative amounts: Different locales format negatives differently. en-US uses -$1.00, some locales use ($1.00) or 1.00- €
  • Zero decimals: When formatting JPY, set maximumFractionDigits: 0 or let Intl handle it automatically based on the currency
  • Large numbers: Intl.NumberFormat handles BigInt as of modern browsers
  • Server-side: Available in Node.js 13+ with full ICU data

Use Case

Every web application that displays prices to international users should use Intl.NumberFormat rather than manual string concatenation. It correctly handles the thousands of locale-currency combinations — including right-to-left locales, narrow symbols, and accounting formats — that would be impractical to implement manually.

Try It — Currency Code Reference

Open full tool