Intl.NumberFormat Basics: Locale-Aware Number Formatting

Learn how Intl.NumberFormat formats numbers differently across locales. Understand decimal separators, digit grouping, and basic number formatting options in JavaScript.

Intl.NumberFormat

Detailed Explanation

Intl.NumberFormat: The Foundation of Locale-Aware Numbers

Intl.NumberFormat is the most frequently used Intl API. It formats numbers according to locale-specific conventions, handling decimal separators, thousands grouping, and digit ordering automatically.

Why Number Formatting Varies by Locale

Different regions use different conventions for displaying numbers:

const num = 1234567.89;

new Intl.NumberFormat('en-US').format(num);  // "1,234,567.89"
new Intl.NumberFormat('de-DE').format(num);  // "1.234.567,89"
new Intl.NumberFormat('fr-FR').format(num);  // "1 234 567,89"
new Intl.NumberFormat('hi-IN').format(num);  // "12,34,567.89"

Notice the differences:

  • English (US): comma for grouping, period for decimal
  • German: period for grouping, comma for decimal
  • French: narrow no-break space for grouping, comma for decimal
  • Hindi (India): uses the Indian numbering system (lakhs and crores)

Key Options

new Intl.NumberFormat(locale, {
  minimumFractionDigits: 2,  // Always show 2 decimal places
  maximumFractionDigits: 2,  // Never show more than 2
  useGrouping: true,         // Enable thousands separators
  signDisplay: 'auto',       // Show minus sign for negatives
});

The useGrouping Option

The useGrouping option controls whether digit grouping separators are used. It accepts:

  • true (default): Use locale-specific grouping
  • false: No grouping separators
  • "min2": Only group if there are at least 2 digits in a group
  • "always": Always use grouping (same as true in most locales)

Browser Support

Intl.NumberFormat is supported in all modern browsers (Chrome 24+, Firefox 29+, Safari 10+, Edge 12+) and Node.js 0.12+. It is one of the most widely supported Intl APIs.

Use Case

Number formatting is essential for any application that displays numbers to international users. E-commerce platforms must format prices, analytics dashboards show metrics, and financial applications display account balances. Without proper locale formatting, a German user seeing '1,234.56' might read it as approximately one thousand two hundred thirty-four, while an American user seeing '1.234,56' would be confused. Using Intl.NumberFormat eliminates these ambiguities.

Try It — Locale String Tester

Open full tool