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.

var 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);

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

// 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));
}

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
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Intl › NumberFormat
Intl.NumberFormat - JavaScript | MDN
In order to get the format of the language used in the user interface of your application, make sure to specify that language (and possibly some fallback languages) using the locales argument: ... const number = 123456.789; // German uses comma as decimal separator and period for thousands console.log(new Intl.NumberFormat("de-DE").format(number)); // 123.456,789 // Arabic in most Arabic speaking countries uses real Arabic digits console.log(new Intl.NumberFormat("ar-EG").format(number)); // ١٢٣٤٥٦٫٧٨٩ // India uses thousands/lakh/crore separators console.log(new Intl.NumberFormat("en-IN").format(number)); // 1,23,456.789 // the nu extension key requests a numbering system, e.g.
🌐
Elijah Manor
elijahmanor.com › blog › format-js-numbers
Natively Format JavaScript Numbers
August 14, 2020 - NOTE: This post is a sibling post to Natively Format JavaScript Dates and Times · When I've needed to format numbers in JavaScript I usually used Number.prototype.toFixed(), found a 3rd party library, or manually manipulated the number to suite my needs. However, with modern browsers, there's a lot of really interesting capabilities you could start using with Number.prototype.toLocaleString() or Intl.NumberFormat.
Discussions

javascript - How to format numbers? - Stack Overflow
I want to format numbers using JavaScript. For example: 10 => 10.00 100 => 100.00 1000 => 1,000.00 10000 => 10,000.00 100000 => 100,000.00 More on stackoverflow.com
🌐 stackoverflow.com
Formatting a number with commas as a thousand digits without converting it into a string
I’ve tried this but when I checked it with console.log(isNaN(conversion));, it returns true. How do you format this without it converting into a string? const income = Number(8000); const conversion = income.toLocaleString(navigator.language, { minimumFractionDigits: 2 }); console.log(is... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
1
1
March 7, 2022
Javascript Formatting numbers with commas
Carlo Sabogal is having issues with: My level of js is very basic. Currently I am learning about basic number operations. My question is: How do you display numbers on the screen wi... More on teamtreehouse.com
🌐 teamtreehouse.com
5
May 15, 2015
Javascript number formatting
Hey Guys -- I have the following line in a Javascript onLoad event: ctrlTax.setValue((ctrlSubtotal.getValue()) * ctrlTaxRate.getValue()); Math works fine, but I cannot get the displayed output to format with only 2 decimal points (nnn.nn vx nnn.nnnnnnn). I have tried adding parseFloat() / ... More on asprunner.com
🌐 asprunner.com
🌐
Yogesh Chavan
blog.yogeshchavan.dev › best-way-format-and-manipulate-numbers-in-javascript
How to Format And Manipulate Numbers In JavaScript
October 2, 2021 - Sometimes we need to add commas in long numbers to easily understand it. It's very difficult to handle all the scenarios ourselves. So to make our task easier there is a library known as Numeral. Let's understand how to use it. There are two ways of using it. ... We will use the second way of npm. To install the package, execute the following command: ... const kFormatted = numeral(23000).format("0a"); const mFormatted = numeral(1230974).format("0.000a"); console.log(kFormatted); // 23k console.log(mFormatted); // 1.321m
🌐
W3Schools
w3schools.com › js › js_number_methods.asp
JavaScript Number Methods
The valueOf() method is used internally in JavaScript to convert Number objects to primitive values.
Top answer
1 of 16
325

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.

var 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);

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

// 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));
}

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
74

Use

num = num.toFixed(2);

Where 2 is the number of decimal places

Edit:

Here's the function to format number as you want

function 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, '2');
    }
    return x1 + x2;
}

Sorce: www.mredkj.com

🌐
Vultr Docs
docs.vultr.com › javascript › examples › format-numbers-as-currency-strings
JavaScript Program to Format Numbers as Currency Strings | Vultr Docs
December 20, 2024 - This JavaScript code listens for changes in an input field (priceInput), formats the entered value as a US Dollar string, and immediately displays the formatted value in another HTML element (formattedPrice). Allow users to select their preferred currency. Format numbers based on the selected currency dynamically.
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 - Learn common number formatting operations, such as rounding, padding, optional decimal marks, currency, seconds, bytes, and more.
🌐
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); }
🌐
David Berri
dberri.com › formatting-numbers-in-javascript
Formatting numbers in JavaScript
November 3, 2021 - So, when I say we are going to ... way to represent numbers is like so: 1.234.567,89. The comma is the decimal separator and the period is the thousands separators....
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Intl › NumberFormat › NumberFormat
Intl.NumberFormat() constructor - JavaScript | MDN
January 25, 2026 - The unit formatting style to use in unit formatting. Possible values are: ... E.g., 16 l. ... E.g., 16 litres. The following properties are also supported by Intl.PluralRules. ... The minimum number of integer digits to use. A value with a smaller number of integer digits than this number will be left-padded with zeros (to the specified length) when formatted.
🌐
Landbot
help.landbot.io › article › aihnj7s81x-different-ways-to-format-numbers-with-js
Different ways to format numbers with JS - Landbot Help
December 10, 2024 - As we created the value with Javascript, we need to add an input from the user so the value is available in Landbot scope: In the send a message we can already display the new value with the new variable: First, we ask for a number and store it in the @number variable · With a Code Set block we add the function that will transform the number: const num1 = @number; function formatNumber(num1) { const decimalNumber = num1.toFixed(2); const [integerPart, decimalPart] = decimalNumber.split('.'); const formattedInteger = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ","); return `${formattedInteger}.${decimalPart}`; } const formattedNumber = formatNumber(num1); return formattedNumber;
🌐
date-fns
date-fns.org › docs › Getting-Started
date-fns - modern JavaScript date utility library
date-fns provides the most comprehensive yet simple and consistent toolset for manipulating JavaScript dates in a browser & Node.js.
🌐
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 - With this, the numbers will now be formatted as follows: ... The numbers we are printing are monetary values so they are missing a decimal value and a currency symbol. One way we can do this is by using JavaScript template literals to append and prepend the pieces we are missing.
🌐
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 - For example, 14340 would be $14,340.00 ... and style. And you can convert these numbers into currencies using the Intl.NumberFormat() method in JavaScript....
🌐
Oreate AI
oreateai.com › blog › unpacking-the-js-format-number-more-than-just-digits › 337aa997f045a628d09d4ed7083e8807
Unpacking the 'Js Format Number': More Than Just Digits - Oreate AI Blog
3 weeks ago - They allow for control over decimal places, leading zeros, negative number formatting (like putting them in parentheses), and crucially, the inclusion of digit grouping symbols – those handy commas that break up long numbers. In JavaScript, while there isn't a single built-in function named formatNumber() that mirrors the VBScript or XSLT versions directly, the functionality is readily available through various methods and custom implementations.
🌐
Asprunner
asprunner.com › forums › topic › 21955-javascript-number-formatting
Javascript number formatting
Hey Guys -- I have the following line in a Javascript onLoad event: ctrlTax.setValue((ctrlSubtotal.getValue()) * ctrlTaxRate.getValue()); Math works fine, but I cannot get the displayed output to format with only 2 decimal points (nnn.nn vx nnn.nnnnnnn). I have tried adding parseFloat() / ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Number › toLocaleString
Number.prototype.toLocaleString() - JavaScript | MDN
In order to get the format of the language used in the user interface of your application, make sure to specify that language (and possibly some fallback languages) using the locales argument: ... const number = 123456.789; // German uses comma as decimal separator and period for thousands console.log(number.toLocaleString("de-DE")); // 123.456,789 // Arabic in most Arabic speaking countries uses Eastern Arabic digits console.log(number.toLocaleString("ar-EG")); // ١٢٣٤٥٦٫٧٨٩ // India uses thousands/lakh/crore separators console.log(number.toLocaleString("en-IN")); // 1,23,456.789 // the nu extension key requests a numbering system, e.g.