What You'll Learn
You'll learn how to format numbers with proper locale-specific formatting—thousands separators, decimal points, and digit grouping—automatically adapted to different regions.
The Problem Intl.NumberFormat Solves
Different countries format numbers differently. In the US, one million is written 1,000,000.50. In Germany, it's 1.000.000,50. In India, it's 10,00,000.50 (different grouping!). Manually handling these variations is error-prone and tedious.
Intl.NumberFormat is a built-in JavaScript class that formats numbers according to locale conventions automatically.
Basic Usage
Create a formatter by passing a locale string:
const usFormatter = new Intl.NumberFormat('en-US');
console.log(usFormatter.format(1234567.89));
// "1,234,567.89"
const deFormatter = new Intl.NumberFormat('de-DE');
console.log(deFormatter.format(1234567.89));
// "1.234.567,89"
const inFormatter = new Intl.NumberFormat('en-IN');
console.log(inFormatter.format(1234567.89));
// "12,34,567.89" (notice the different grouping!)
Using the User's Locale
You can omit the locale to use the user's browser/system default:
const defaultFormatter = new Intl.NumberFormat();
console.log(defaultFormatter.format(9876543.21));
// Formats according to user's locale settings
How It Works
Think of Intl.NumberFormat as a translator for numbers. You give it a number and a locale (like "speak German" or "speak American English"), and it translates that number into the proper written format for that region—commas, periods, spacing, and grouping all handled automatically.
The format() method does the actual conversion, returning a properly formatted string.
Key Takeaway: Intl.NumberFormat automatically formats numbers with locale-specific separators and grouping rules, eliminating the need for manual string manipulation across different regions.