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
🌐
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.
🌐
DEV Community
dev.to › nikolasbarwicki › formatting-big-numbers-using-intlnumberformat-5397
How to easily format numbers with vanilla Javascript - DEV Community
March 2, 2023 - But there's easier method - Javascript will do this for you with the help of Intl object. In this short article we will focus only on Intl.NumberFormat object with enables number formatting
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
How to format number with set amount of whitespace
String. padEnd() '1'.padEnd(3, ' ') + 'text'; '11'.padEnd(3, ' ') + 'text'; Evaluates to: '1 text' '11 text' More on reddit.com
🌐 r/learnjavascript
2
2
August 4, 2022
🌐
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.
🌐
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
Find elsewhere
🌐
RSWP Themes
rswpthemes.com › home › javascript tutorial › how to format numbers in javascript with commas
How to Format Numbers in JavaScript with Commas
January 12, 2024 - This step-by-step guide will walk you through the process of formatting numbers with commas in JavaScript.
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.
🌐
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.
🌐
DEV Community
dev.to › ratracegrad › how-to-format-numbers-in-javascript-using-intlnumberformat-34o5
How to Format Numbers in JavaScript using Intl.NumberFormat - DEV Community
May 11, 2022 - Here is an example of how we use to format numbers using .toLocaleString(): const money = 1000; money.toLocaleString('en-US', { style: 'currency', currency: 'USD' }); // $1,000.00 · Now with ES6 JavaScript gives us the Intl object which is the ECMAScript Internationalization API.
🌐
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.