Course contentsShow
← JavaScript
Lesson 2202 of 2,72346. InternationalizationFree lesson

Currency Formatting

Format monetary values with the currency code and display options like symbol or name.

Currency Formatting

What you'll learn: How to format monetary values with currency codes and display them as symbols or full names using Intl.NumberFormat.

The Core Idea

When formatting currency, you need more than just numbers—you need to specify which currency (USD, EUR, JPY, etc.) and how to display it. Intl.NumberFormat handles this elegantly through the style: 'currency' option combined with additional properties that control whether you see symbols like "$" or full names like "US dollars."

Specifying the Currency Code

When you set style: 'currency', you must also provide a currency option using the three-letter ISO 4217 currency code:

const usdFormatter = new Intl.NumberFormat('en-US', {
  style: 'currency',
  currency: 'USD'
});

console.log(usdFormatter.format(1234.56)); // "$1,234.56"

Without the currency option, you'll get an error—the formatter needs to know which currency to display.

Controlling the Display: Symbol vs Name

The currencyDisplay option lets you choose how the currency appears:

  • 'symbol' (default): Shows "$", "€", etc.
  • 'narrowSymbol': Uses compact symbols when available
  • 'code': Shows "USD", "EUR", etc.
  • 'name': Shows "US dollars", "euros", etc.
const eurName = new Intl.NumberFormat('en-US', {
  style: 'currency',
  currency: 'EUR',
  currencyDisplay: 'name'
});

console.log(eurName.format(1234.56)); // "1,234.56 euros"

Key Takeaway: Currency formatting requires the currency code (e.g., 'USD') and lets you customize display via currencyDisplay to show symbols, codes, or full currency names—essential for international monetary presentation.