Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST TOOLS

JS Tutorial

JS Syntax

JS Operators

JS If Conditions

JS Loops

JS Strings

JS Numbers

JS Functions

JS Objects

JS Scope

JS Dates

JS Temporal  New

JS Arrays

JS Sets

JS Maps

JS Iterations

JS Math

JS RegExp

JS Data Types

JS Errors

JS Debugging

JS Style Guide

JS Reference

JS Projects New

JS 2026

JS HTML DOM

JS HTML Events


JS Advanced


JS Functions

JS Objects

JS Classes

JS Asynchronous

JS Modules

JS Meta & Proxy

JS Typed Arrays

JS DOM Navigation

JS Windows

JS Web API

JS AJAX

JS JSON

JS jQuery

JS Graphics

JS Examples

JS Reference


JavaScript 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

In this example it is used on a Number (num).

let num = 1234567.89;

let text = num.toLocaleString();
Try it Yourself »

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");
Try it Yourself »

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"});
Try it Yourself »

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"});
Try it Yourself »

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
});
Try it Yourself »

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");
Try it Yourself »

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"
});
Try it Yourself »


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);
Try it Yourself »

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");
Try it Yourself »


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.

-->