Edit: Sept 18, 2019

Since new APIs are available, thought it would be helpful to point out that you can do this much more simply using toLocaleString options:

const numbers = [1, 1000, 2345.67, 21589.334719999995];
const options = { 
  minimumFractionDigits: 2,
  maximumFractionDigits: 2 
};
numbers.forEach(num => {
  const formatted = Number(num).toLocaleString('en', options);
  console.log(formatted);
});


original answer

To add the commas, you could use:

n = parseFloat(n).toFixed(2)
var withCommas = Number(n).toLocaleString('en');

Here is a fiddle

Answer from Rob M. on Stack Overflow
🌐
Medium
medium.com › @noffybarudwale › javascript-format-numbers-with-commas-and-decimals-86b68ec5b180
JavaScript : Format numbers with commas and decimals. | by Nofij Barudwale | Medium
October 13, 2021 - This will format the number with commas at the thousands of places and return a string with the formatted number. The following example shows how it works: value: the number which we want to add commas. decimal: the number of digits after decimal points. It should be a number like 1,2 and 3 etc. here you can specify Language. like ‘en-IN’ , ‘ja-JP’,’en-US’ and ‘de-DE’, etc. Output will looks like: JavaScript ·
🌐
W3Schools
w3schools.com › howto › howto_js_format_number_dec.asp
How To Format a Number with Two Decimals
let num = 5.56789; let n = ... let n = num.toFixed(3); // 5.568 Try it Yourself » · Tip: Learn more about the toFixed() method in our JavaScript Reference....
🌐
Stack Abuse
stackabuse.com › bytes › format-numbers-with-commas-in-javascript
Format Numbers with Commas in JavaScript
August 7, 2023 - However, keep in mind that toLocaleString() will keep all digits after the decimal. So 1234567.890123 would become "1,234,567.890123". If you need a bit more control over the formatting, regular expressions can help: function formatNumberWithCommas(number) { return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); } const number = 1234567.89; console.log(formatNumberWithCommas(number)); // Outputs: "1,234,567.89" Link: This function uses regular expressions to insert commas after every third digit from right to left, providing the desired formatting.
🌐
Crio
crio.do › blog › format-numbers-with-commas-as-thousands-separators-2025-javascript-criodo
How to Format a Number with Commas as Thousands Separators?
December 26, 2024 - Supports additional options, like setting minimum or maximum decimal places. Additional examples: console.log(num.toLocaleString("en-US", { minimumFractionDigits: 2 })); // "1,234,567.89" console.log(num.toLocaleString("de-DE")); // "1.234.567,89" (German locale) Using Intl.NumberFormat A more advanced method for custom formatting: const formatter = new Intl.NumberFormat("en-US"); console.log(formatter.format(1234567.89)); // Output: "1,234,567.89" Handling Large Numbers JavaScript has a maximum safe integer value (9007199254740991).
🌐
GreenSock
gsap.com › helper functions › formatnumber
formatNumber | GSAP | Docs & Learning
// adds commas and forces 2 decimal places. function formatNumber(value, decimals) { let s = (+value).toLocaleString("en-US").split("."); return decimals ?
🌐
Byby
byby.dev › js-format-numbers-commas
How to format numbers with commas in JavaScript
The usage of commas (,) and periods (.) as decimal separators and thousands separators varies based on the conventions of different regions and countries.
Find elsewhere
🌐
DEV Community
dev.to › onlinemsr › big-numbers-no-worries-javascript-format-number-with-commas-n6j
Big Numbers, No Worries: JavaScript Format Number With Commas - DEV Community
March 23, 2024 - Look at this example of using toFixed() in JavaScript: // Format number with comma using toFixed() var number = 123456789.123; // Convert the numberber into a string, with two decimal places var fixednumber = number.toFixed(2); // Split the ...
🌐
Reddit
reddit.com › r/flask › how to format a number with comma and 2 decimal?
r/flask on Reddit: How to format a number with comma and 2 decimal?
November 4, 2021 -

I am trying to format a number like this 250,000.50

What I have tried

<td style="text-align:right;">${{"{0:,.2f}"|format(data[0]['amount']) }} </td>

<td style="text-align:right;">${{"{:0.2f}"|format(data[0]['amount']) }} </td>

<td style="text-align:right;">${{"{0:%.2f}"|format(data[0]['amount']) }} </td>

data[0]['amount']contains 250000.505050

🌐
EyeHunts
tutorial.eyehunts.com › home › javascript format number with commas and decimal places | example
JavaScript format number with commas and decimal places | Code
December 13, 2022 - // With custom settings, forcing a "US" locale to guarantee commas in output let number2 = 1234.56789; // floating point example number2.toLocaleString('en-US', {maximumFractionDigits:2}) // "1,234.57"
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-format-a-number-with-two-decimals-in-javascript
How to Format a Number with Two Decimals in JavaScript? - GeeksforGeeks
July 23, 2025 - By multiplying the number by 100, rounding it, and then dividing by 100, we effectively round the number to two decimal places.
🌐
CopyProgramming
copyprogramming.com › howto › javascript-format-number-with-commas-and-2-decimal
Formatting numbers in JavaScript with 2 decimal places and commas - Javascript
May 9, 2023 - By following the structure defined in {{ value_expression | number [ : digitsInfo [ : locale ] ] }} as per the official Angular documentation for the DecimalPipe, I could successfully format the desired number. ... By providing an empty string ( '' ), the default values for digitsInfo are applied ...
🌐
MSR
rajamsr.com › home › javascript format number with commas: 5 best ways
JavaScript Format Number with Commas: 5 Best Ways | MSR - Web Dev Simplified
March 19, 2024 - Look at this example of using toFixed() in JavaScript: // Format number with comma using toFixed() var number = 123456789.123; // Convert the numberber into a string, with two decimal places var fixednumber = number.toFixed(2); // Split the ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Intl › NumberFormat
Intl.NumberFormat - JavaScript | MDN
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.
🌐
Medium
medium.com › @onlinemsr › big-numbers-no-worries-javascript-format-number-with-commas-17ec7f878834
Big Numbers, No Worries: JavaScript Format Number With Commas
March 23, 2024 - Learn how to use JavaScript format numbers with commas to display numbers in a readable way. An easy and practical guide.