🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to JavaScript Notes
Topic #101

JS toLocaleString()

The toLocaleString() method converts a value to a string, using local formatting rules.

The toLocaleString() method is especially useful for formatting numbers, dates, arrays, currencies, and percentages for different countries.

The toLocaleString() Method

The toLocaleString() method is available for many JavaScript datatypes / objects:

  • Numbers
  • Dates
  • Arrays
  • BigInts

Example

let num = 1234567.89;

let text = num.toLocaleString();

Using Locales

You can specify a language and country code to format a value for a specific locale.

Example

let num = 1234567.89;

let us = num.toLocaleString("en-US");

let de = num.toLocaleString("de-DE");

let no = num.toLocaleString("no-NO");

Formatting Currency

With options, toLocaleString() can format numbers as currency.

Example

let price = 1299.95;

let dollars = price.toLocaleString("en-US",

{style:"currency", currency:"USD"});

let euros = price.toLocaleString("de-DE",

{style:"currency", currency:"EUR"});

let kroner = price.toLocaleString("no-NO",

{style:"currency", currency:"NOK"});

Formatting Percentages

The style:"percent" option formats a number as a percentage.

Example

let score = 0.875;

let result = score.toLocaleString("en-US", {style:"percent"});

Controlling Decimal Digits

You can control the number of decimal digits with minimumFractionDigits and maximumFractionDigits.

Example

let num = 3.14159;

let text = num.toLocaleString("en-US", {

  minimumFractionDigits: 2,

  maximumFractionDigits: 2

});

Note: The method name is toLocaleString(), not toLocalString(). The word locale means a language and country format, such as "en-US", "de-DE", or "no-NO".


Formatting Dates

Dates can also be formatted with toLocaleString().

Example

let date = new Date();

let text = date.toLocaleString("en-US");

Date Formatting Options

Many options can be used to control how dates are displayed.

Example

let date = new Date();

let text = date.toLocaleString("en-US", {

  weekday: "long",

  year: "numeric",

  month: "long",

  day: "numeric"

});

A Clever Use: Readable File Sizes

A clever use of toLocaleString() is to make file sizes easier to read.

Example

function fileSize(bytes) {

  if (bytes < 1024) return bytes + " bytes";

  if (bytes < 1024 * 1024) return (bytes / 1024).toLocaleString("en-US", {maximumFractionDigits: 1}) + " KB";

  return (bytes / 1024 / 1024).toLocaleString("en-US", {maximumFractionDigits: 1}) + " MB";

}

let size = 1536000;

let text = fileSize(size);

Arrays and toLocaleString()

For arrays, the toLocaleString() methods converts each array element.

Example

const dates = [

  new Date("2026-01-01"),

  new Date("2026-12-24")

];

let text = dates.toLocaleString("en-US");

Want to go beyond the notes?

Join CodingNow 2.0's JavaScript course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

JS toLocaleString() – FAQs

Quick answers about learning JS toLocaleString() in JavaScript.

This free note from CodingNow 2.0 explains JS toLocaleString() in JavaScript — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every JavaScript topic on CodingNow 2.0, including JS toLocaleString(), is 100% free with no signup required.
With focused practice, most students grasp JS toLocaleString() in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now