Course contentsShow
← JavaScript
Lesson 1645 of 2,72335. Standard Library and Built-insFree lesson

Currency Formatting with NumberFormat

Display monetary values with correct currency symbols, codes, and decimal places per locale.

Currency Formatting with NumberFormat

You'll learn how to display monetary values correctly formatted for any currency and locale using Intl.NumberFormat.

The Problem with Manual Currency Formatting

Currencies differ wildly around the world. The US uses $10.99, the EU might show 10,99 €, Japan displays ¥1,099, and the UK writes £10.99. Handling these variations manually—symbol position, decimal separators, grouping—is error-prone and time-consuming.

How NumberFormat Handles Currency

Intl.NumberFormat accepts a style: 'currency' option along with a currency code (ISO 4217 standard like 'USD', 'EUR', 'JPY'). It automatically adjusts symbols, decimal places, and formatting rules based on the locale.

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

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

const euroFormatter = new Intl.NumberFormat('de-DE', {
  style: 'currency',
  currency: 'EUR'
});

console.log(euroFormatter.format(1234.56)); 
// "1.234,56 €"

const yenFormatter = new Intl.NumberFormat('ja-JP', {
  style: 'currency',
  currency: 'JPY'
});

console.log(yenFormatter.format(1234.56)); 
// "¥1,235" (yen has no fractional units)

Notice how Japanese yen automatically rounds to whole numbers—no manual logic needed. The locale determines how the currency displays, while the currency code determines which currency and its decimal precision.

// Same currency, different locale presentation
const usdInGerman = new Intl.NumberFormat('de-DE', {
  style: 'currency',
  currency: 'USD'
});

console.log(usdInGerman.format(1234.56)); 
// "1.234,56 $" (German number format, US currency)

Key Takeaway: Use Intl.NumberFormat with style: 'currency' and a currency code to automatically format monetary values with proper symbols, decimals, and grouping for any locale—no manual string manipulation required.