If you want to use built-in code, you can use toLocaleString() with minimumFractionDigits.

Browser compatibility for the extended options on toLocaleString() was limited when I first wrote this answer, but the current status looks good. If you're using Node.js, you will need to npm install the intl package.

Use with AIvar value = (100000).toLocaleString(
  undefined, // leave undefined to use the visitor's browser 
             // locale or a string like 'en-US' to override it.
  { minimumFractionDigits: 2 }
);
console.log(value);
Run code snippetEdit code snippet Hide Results Copy to answer Expand

Number formatting varies between cultures. Unless you're doing string comparison on the output,1 the polite thing to do is pick undefined and let the visitor's browser use the formatting they're most familiar with.2

Use with AI// Demonstrate selected international locales
var locales = [
  undefined,  // Your own browser
  'en-US',    // United States
  'de-DE',    // Germany
  'ru-RU',    // Russia
  'hi-IN',    // India
  'de-CH',    // Switzerland
];
var n = 100000;
var opts = { minimumFractionDigits: 2 };
for (var i = 0; i < locales.length; i++) {
  console.log(locales[i], n.toLocaleString(locales[i], opts));
}
Run code snippetEdit code snippet Hide Results Copy to answer Expand

If you are from a culture with a different format from those above, please edit this post and add your locale code.


1 Which you shouldn't.
2 Obviously do not use this for currency with something like {style: 'currency', currency: 'JPY'} unless you have converted to the local exchange rate. You don't want your website to tell people the price is ¥300 when it's really $300. Sometimes real e-commerce sites make this mistake.

Answer from Michael come lately on Stack Overflow
🌐
DEV Community
dev.to › schalkneethling › number-and-currency-formatting-in-javascript-using-intlnumberformat-46og
Number and Currency Formatting in JavaScript using Intl.NumberFormat - DEV Community
April 3, 2024 - As with most things concerning programming, there are many ways to achieve the same end result, this is one of my favorite APIs when formatting numbers in JavaScript. NOTE: Feel free to share how you handle number formatting with JavasScript in the comments. First things first, support for Intl.NumberFormat and the related format function across runtime and browser environments is excellent so you can safely follow this post and use Intl.NumberFormat in production.
Top answer
1 of 16
326

If you want to use built-in code, you can use toLocaleString() with minimumFractionDigits.

Browser compatibility for the extended options on toLocaleString() was limited when I first wrote this answer, but the current status looks good. If you're using Node.js, you will need to npm install the intl package.

Use with AIvar value = (100000).toLocaleString(
  undefined, // leave undefined to use the visitor's browser 
             // locale or a string like 'en-US' to override it.
  { minimumFractionDigits: 2 }
);
console.log(value);
Run code snippetEdit code snippet Hide Results Copy to answer Expand

Number formatting varies between cultures. Unless you're doing string comparison on the output,1 the polite thing to do is pick undefined and let the visitor's browser use the formatting they're most familiar with.2

Use with AI// Demonstrate selected international locales
var locales = [
  undefined,  // Your own browser
  'en-US',    // United States
  'de-DE',    // Germany
  'ru-RU',    // Russia
  'hi-IN',    // India
  'de-CH',    // Switzerland
];
var n = 100000;
var opts = { minimumFractionDigits: 2 };
for (var i = 0; i < locales.length; i++) {
  console.log(locales[i], n.toLocaleString(locales[i], opts));
}
Run code snippetEdit code snippet Hide Results Copy to answer Expand

If you are from a culture with a different format from those above, please edit this post and add your locale code.


1 Which you shouldn't.
2 Obviously do not use this for currency with something like {style: 'currency', currency: 'JPY'} unless you have converted to the local exchange rate. You don't want your website to tell people the price is ¥300 when it's really $300. Sometimes real e-commerce sites make this mistake.

2 of 16
75

Use

Use with AInum = num.toFixed(2);

Where 2 is the number of decimal places

Edit:

Here's the function to format number as you want

Use with AIfunction formatNumber(number)
{
    number = number.toFixed(2) + '';
    x = number.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
}

Sorce: www.mredkj.com

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Intl › NumberFormat › format
Intl.NumberFormat.prototype.format() - JavaScript | MDN
July 20, 2026 - The format() method of Intl.NumberFormat instances formats a number according to the locale and formatting options of this Intl.NumberFormat object.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-intl-numberformat-constructor
JavaScript Intl.NumberFormat() Constructor - GeeksforGeeks
January 13, 2026 - The Intl.NumberFormat() constructor creates an object for formatting numbers based on locale-specific rules, making output readable and region-friendly.
🌐
MDN
mdn2.netlify.app › en-us › docs › web › javascript › reference › global_objects › intl › numberformat › numberformat
Intl.NumberFormat() constructor - JavaScript | MDN
March 29, 2022 - The Intl.NumberFormat() constructor creates Intl.NumberFormat objects that enable language-sensitive number formatting.
🌐
DEV Community
dev.to › orimdominic › formatting-numbers-in-javascript-with-intl-numberformat-5goo
Formatting Numbers in JavaScript with Intl.NumberFormat - DEV Community
August 24, 2024 - It simply means that with Intl.NumberFormat, JavaScript can construct an object that will have the ability to style (or to be technically correct, format) numbers based on human languages.
Find elsewhere
🌐
30 Seconds of Code
30secondsofcode.org › home › javascript › number › number formatting
Formatting numeric values in JavaScript - 30 seconds of code
February 14, 2024 - When working with currency, it's important to use the appropriate formatting. Luckily, JavaScript's Intl.NumberFormat makes this easy, allowing us to format numbers as currency strings.
🌐
Raymond Camden
raymondcamden.com › 2025 › 08 › 22 › unit-formatting-with-intl-in-javascript
Unit Formatting with Intl in JavaScript
August 22, 2025 - I had Googled for this, and Google actually spat out a JavaScript function to do this for me. And... from what I could see... it worked well and was kinda clever. Here's the function it created: function formatBytes(bytes, locale = 'en-US') { const units = ['byte', 'kilobyte', 'megabyte', 'gigabyte', 'terabyte']; const i = Math.floor(Math.log(bytes) / Math.log(1024)); const value = bytes / Math.pow(1024, i); const formatter = new Intl.NumberFormat(locale, { style: 'unit', unit: units[i], unitDisplay: 'narrow', // or 'short', 'long' maximumFractionDigits: 2, // Adjust as needed }); return formatter.format(value); } The clever part comes in from figuring out what 'level' of size to use, from byte to terabyte, but doing a bit of match.
🌐
Is Ray, Not Array
israynotarray.com › home › javascript › javascript number formatting: the easiest way (thousands separators and currency)
JavaScript Number Formatting: The Easiest Way (Thousands Separators and Currency) | Is Ray, Not Array
September 18, 2025 - ····const number = 1234567.89; const formatter = new Intl.NumberFormat('ja-JP', { style: 'currency', currency: 'JPY', }); const formattedCurrency = formatter.format(number); // "¥1,234,568" console.log(formattedCurrency); // "¥1,234,568"
🌐
Medium
medium.com › illumination › 4-number-formatting-methods-in-javascript-245c411b9847
4 Number Formatting Methods in JavaScript | by Biao Zhu | ILLUMINATION | Medium
February 29, 2024 - The toLocaleString method in JavaScript is a powerful tool for formatting numbers based on the user localization settings.
🌐
Numeraljs
numeraljs.com
Numeral.js
A javascript library for formatting and manipulating numbers.
🌐
SimpleLocalize
simplelocalize.io › blog › posts › number-formatting-in-javascript
Number formatting in JavaScript: toLocaleString and Intl.NumberFormat | SimpleLocalize
May 7, 2026 - JavaScript has built-in APIs for locale-aware number formatting that cover the vast majority of i18n use cases without any third-party dependencies. This post focuses on toLocaleString() and Intl.NumberFormat, the two main tools, with practical examples for currencies, percentages, and units.
🌐
W3C
w3c.github.io › i18n-drafts › questions › qa-number-format.en.html
Number, currency, and unit formatting
March 12, 2026 - The Intl.NumberFormat object in JavaScript automatically handles locale-specific decimal and grouping separators, currency symbols, and other numerical conventions.
🌐
Delicious-insights
delicious-insights.com › en › posts › js-number-formatting
Properly formating a number • Delicious Insights
May 6, 2020 - In our situation, we’re mostly interested by the Intl.NumberFormat class, that lets us create extremely detailed and versatile numeric formaters.
🌐
freeCodeCamp
freecodecamp.org › news › how-to-format-number-as-currency-in-javascript-one-line-of-code
How to Format a Number as Currency in JavaScript
November 7, 2024 - You can use the Intl.NumberFormat() constructor to create Intl.NumberFormat objects that enable language-sensitive number formatting, such as currency formatting.
🌐
Format.JS
formatjs.github.io › docs › polyfills › intl-numberformat
Intl Numberformat | FormatJS
A polyfill for ESNext Intl.NumberFormat and Number.prototype.toLocaleString.