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?

Our premium learning platform, created with over a decade of experience and thousands of feedbacks.

Learn and improve your coding skills like never before.

Try Programiz PRO
  • Interactive Courses
  • Certificates
  • AI Help
  • 2000+ Challenges