Course contentsShow
← Web Development
Lesson 2771 of 2,98249. Dates, Times, and Numbers on the WebFree lesson

Intl.NumberFormat Basics

Formatting numbers with locale-specific digit grouping, decimal separators, and symbols.

What You'll Learn

You'll learn how to format numbers with locale-specific conventions like thousand separators, decimal points, and currency symbols using JavaScript's built-in Intl.NumberFormat API.

Why Numbers Need Locale Formatting

Numbers look different around the world. Americans write "1,234.56" while Germans write "1.234,56" and French write "1 234,56". The Intl.NumberFormat API automatically handles these cultural differences, just like Intl.DateTimeFormat handles date conventions.

Creating a NumberFormat Instance

You create a formatter by specifying a locale (or letting the browser detect it):

// Use user's locale
const formatter = new Intl.NumberFormat();
console.log(formatter.format(1234567.89));
// US: "1,234,567.89"
// DE: "1.234.567,89"

// Specify a locale explicitly
const usFormatter = new Intl.NumberFormat('en-US');
console.log(usFormatter.format(1234.5)); // "1,234.5"

const deFormatter = new Intl.NumberFormat('de-DE');
console.log(deFormatter.format(1234.5)); // "1.234,5"

Common Use Cases

Formatting prices with proper separators:

const price = new Intl.NumberFormat('en-US');
console.log(price.format(9999.99)); // "9,999.99"

Different locales, different rules:

const frFormatter = new Intl.NumberFormat('fr-FR');
console.log(frFormatter.format(1234567.89)); // "1 234 567,89"

Think of Intl.NumberFormat as a translator between your raw numeric data and the visual expectations of your users' cultures—it automatically adapts digit grouping (commas vs periods vs spaces) and decimal separators based on locale.

Key Takeaway: Intl.NumberFormat formats numbers according to locale-specific conventions for digit grouping and decimal separators, eliminating the need to manually handle cultural number formatting differences.