JavaScript Number.toLocaleString()

The syntax of the toLocaleString() method is:

num.toLocaleString(locales, options)

Here, num is a number.


toLocaleString() Parameters

The toLocaleString() method takes in:

  • locales (Optional) - A string specifying which language specific format to use.
  • options (Optional) - An object with configuration properties.

To learn more, visit Intl.NumberFormat() constructor.


Return value from toLocaleString()

  • Returns a string with a language-sensitive representation of the given number.

Example: Using toLocaleString() method

let number = 400000;
console.log(number.toLocaleString()); // 400,000 if in US English locale

// using locales
let number1 = 123456.789;

// India uses thousands/lakh/crore separators
console.log(number1.toLocaleString("en-IN")); // 1,23,456.789

// using options
let currency = number1.toLocaleString("de-DE", {
  style: "currency",
  currency: "EUR",
  maximumSignificantDigits: 3,
});
console.log(currency); // 123.000 €

Output

400,000
1,23,456.789
123.000 €

Recommended Reading:

Did you find this article helpful?

Your builder path starts here. Builders don't just know how to code, they create solutions that matter.

Escape tutorial hell and ship real projects.

Try Programiz PRO
  • Real-World Projects
  • On-Demand Learning
  • AI Mentor
  • Builder Community