Back to JavaScript Notes
Topic #357

toLocaleString

By the end of this lesson, you will be able to format JavaScript numbers and dates for different locales using toLocaleString() and common options.

What it is

toLocaleString() is a built-in method on Number and Date objects that returns a string formatted according to a locale and optional formatting rules. Think of it as asking the JavaScript runtime: “How would a person in this locale naturally read this number or date?”

Related terms include locale (such as en-US or de-DE), Intl (the internationalization API), Intl.NumberFormat, and Intl.DateTimeFormat. In practice, toLocaleString() is a convenience wrapper around those formatters.

Why it matters

  • It shows numbers with the correct decimal separator, thousands separator, and currency symbol.
  • It formats dates and times in a way users expect for their region.
  • It reduces manual string building and avoids hard-coded formats like MM/DD/YYYY.
  • It helps applications support multiple languages and regions with the same code.
  • It improves accessibility and trust by presenting familiar numeric and date patterns.

Syntax or steps

The basic pattern is:

value.toLocaleString(locale, options);

For numbers, useful options include style, currency, minimumFractionDigits, maximumFractionDigits, and useGrouping. For dates, useful options include dateStyle, timeStyle, timeZone, weekday, month, day, year, hour, and minute.

If you omit locale, the runtime uses the default locale. If you omit options, it uses a general locale-appropriate format.

Example

const amount = 1234.56;
const date = new Date('2026-01-15T09:30:00Z');

console.log(amount.toLocaleString('en-US', {
  style: 'currency',
  currency: 'USD'
}));

console.log(amount.toLocaleString('de-DE', {
  minimumFractionDigits: 2,
  maximumFractionDigits: 2
}));

console.log(date.toLocaleString('en-GB', {
  dateStyle: 'medium',
  timeStyle: 'short'
}));

console.log(date.toLocaleString('ja-JP', {
  timeZone: 'Asia/Tokyo',
  dateStyle: 'full'
}));

Part by part:

  • amount.toLocaleString('en-US', { style: 'currency', currency: 'USD' }) formats the number as US dollars.
  • amount.toLocaleString('de-DE', { minimumFractionDigits: 2, maximumFractionDigits: 2 }) formats the same number using German conventions, such as a comma for the decimal separator.
  • date.toLocaleString('en-GB', { dateStyle: 'medium', timeStyle: 'short' }) formats the date and time for British English.
  • date.toLocaleString('ja-JP', { timeZone: 'Asia/Tokyo', dateStyle: 'full' }) converts the date to Tokyo time and formats it for Japanese.

Common mistakes

  • Assuming the output is fixed. The result depends on the locale and runtime. Do not compare formatted strings for logic; compare the original number or date.
  • Forgetting the currency code. { style: 'currency' } without currency throws an error. Always provide a valid ISO currency code such as USD or EUR.
  • Using it on a string. '1234.5'.toLocaleString() does not format the number. Convert first with Number() or parseFloat().
  • Ignoring time zones. A Date represents an instant, but formatting can shift the displayed time. Use timeZone when the user’s region matters.

When to use it

Use toLocaleString() when you need a quick, readable string for display. Use Intl.NumberFormat or Intl.DateTimeFormat when you need reusable formatters or more control.

ApproachBest forTrade-off
toLocaleString()One-off display formattingConvenient, but creates a formatter each call
Intl.NumberFormat / Intl.DateTimeFormatRepeated formatting or shared optionsSlightly more setup, better performance
Manual string formattingFixed internal formats, such as logs or APIsFast, but not locale-aware

Practice

Guided exercise: Format 9876543.21 as US dollars with two decimal places, then format new Date('2026-03-01T14:00:00Z') for en-GB with medium date and short time.

Challenge: Format 1234567.891 as euros with grouping, and format the same date for Asia/Tokyo using a full date style.

Hint: Use { style: 'currency', currency: 'EUR' } for euros and { timeZone: 'Asia/Tokyo', dateStyle: 'full' } for the date.

Quick check

What does (1234.5).toLocaleString('de-DE') do?

It returns a string formatted using German conventions, typically showing a comma as the decimal separator and a period or space as the grouping separator, depending on the runtime.

Summary

toLocaleString() turns numbers and dates into locale-aware display strings without manual formatting. It is ideal for user-facing output, while Intl formatters are better when you need reusable, high-performance formatting.

Want to go beyond the notes?

Join Coding Now Tech Institute's JavaScript course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

toLocaleString – FAQs

Quick answers about learning toLocaleString in JavaScript.

This free note from Coding Now Tech Institute explains toLocaleString in JavaScript — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every JavaScript topic on Coding Now Tech Institute, including toLocaleString, is 100% free with no signup required.
With focused practice, most students grasp toLocaleString in 1–3 days from these notes; pairing it with Coding Now Tech Institute'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 Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now