Yes remove the commas:

let output = parseFloat("2,299.00".replace(/,/g, ''));
console.log(output);

Answer from Sam on Stack Overflow
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-parse-string-with-comma-to-number
Parse a String with Commas to a Number in JavaScript | bobbyhadz
March 3, 2024 - Strings are immutable in JavaScript. We replace each comma in the string with an empty string in order to remove the commas. The last step is to call the parseFloat() function with the result.
Discussions

javascript - How to add comma in a number in string - Stack Overflow
So I know how to add a comma on numbers (toLocaleString.()) and this function requires integer or decimal value as a parameter. I need this result with 2 digit decimal value. It does run and return... More on stackoverflow.com
🌐 stackoverflow.com
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
String to number - comma separator
Hi friends I would like some help. I have a column, that I have read from a CSV file. On my CSV node, into the “transformation” tab, I always set the column with a String to change later. I’m from Brazil and the number decimal’s separator is comma “,” and the thousands is “dot” ... More on forum.knime.com
🌐 forum.knime.com
1
0
July 24, 2023
javascript - How can I format a number with commas as thousands separators? - Stack Overflow
I am trying to print an integer in JavaScript with commas as thousands separators. For example, I want to show the number 1234567 as "1,234,567". How would I go about doing this? Here is ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Sabe
sabe.io › blog › javascript-parse-string-commas-to-number
How to Parse String with Commas to Number in JavaScript | Sabe
June 17, 2022 - The most straightforward way to convert a string with commas into a number is to simply remove the commas in the string first. ... Now we'll use the replace method to globally replace all commas with an empty string, essentially removing the ...
🌐
DEV Community
dev.to › dhairyashah › how-to-seperate-number-with-commas-in-javascript-550k
How to seperate number with commas in Javascript - DEV Community
November 6, 2022 - The toLocalString() is a default built-in browser method of the Number object that returns the number (in string) representing the locale. You can pass any locale inside the parantheses as a parameter. const number = 14500240 const formatedNumber = number.toLocaleString("en-IN") console.log(formatedNumber) function numberWithCommas(num) { return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ','); } const number = numberWithCommas(234234.555); console.log(number);
🌐
Medium
medium.com › @renatello › how-to-separate-numbers-with-commas-in-javascript-66dcdb36f5f0
How to separate numbers with commas in JavaScript | by Renat Galyamov | Medium
August 27, 2019 - In this tutorial, you’ll learn ...).toLocaleString() // → 123,456 · You can create a function that will take a string, convert it to a number and split this number with commas....
🌐
YouTube
youtube.com › watch
Number to String with Commas in JavaScript - YouTube
👉 Source code: https://openjavascript.info/2022/05/24/converting-a-number-to-string-with-commas-javascript/⚡ Looking for high-performance, afforable web hos...
Published   June 1, 2022
🌐
sebhastian
sebhastian.com › javascript-format-number-commas
JavaScript format number with commas (example included) | sebhastian
July 8, 2022 - You can use the regex pattern in combination with String.replace() to replace the markers with commas. ... function numberWithCommas(num) { return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ','); } let n = numberWithCommas(234234.555); ...
Find elsewhere
🌐
Favtutor
favtutor.com › articles › format-numbers-commas-javascript
Format Numbers with Commas in JavaScript (with code)
February 5, 2024 - By using regex we can search for specific patterns in a string and replace them with the desired values. Here regex can be used to add commas to format a number.
🌐
Seanmcp
seanmcp.com › articles › be-careful-parsing-formatted-numbers-in-javascript
Be careful parsing formatted numbers in JavaScript – seanmcp.com
December 20, 2022 - Unfortunately, parseFloat and the ... says you probably shouldn't be using it like this anyway. The solution is to remove the commas before parsing....
Top answer
1 of 3
7

You can specify the exact number of decimal digits in your options, which is the second parameter in toLocaleString()

const number = 24242324.5754;

number.toLocaleString('en-US', {
    minimumFractionDigits: 2,
    maximumFractionDigits: 2
})

// result is: 24,242,324.58

See also MDN doc here

minimumFractionDigits

The minimum number of fraction digits to use. Possible values are from 0 to 20; the default for plain number and percent formatting is

maximumFractionDigits

The maximum number of fraction digits to use. Possible values are from 0 to 20; the default for plain number formatting is the larger of minimumFractionDigits and 3

2 of 3
1

The toFixed() method returns a string but the toLocaleString() method expects a number so just convert your string to a number after using the toFixed() method with the parseFloat() function and then use the toLocaleString() method on it.

However, do note that you will have to manually append the leading 0 since the parseFloat() method removes any leading zeroes to the right of the decimal point.

Check this particular answer on another Stack Overflow thread that explains the reason why the parseFloat() method removes the leading zeroes after the decimal point.


var num = 66666.7
var parsedNum = (""+num).split('.')[1].length > 1 ?
    parseFloat(num.toFixed(2)).toLocaleString() : 
    parseFloat(num.toFixed(2)).toLocaleString() + '0';

console.log("original", num)
console.log("with comma", num.toLocaleString())
console.log("with 2 digit fixed", num.toFixed(2))
console.log("now working--", parsedNum)

🌐
Code Boxx
code-boxx.com › home › 3 ways to add comma to numbers in javascript (thousands separator)
3 Ways To Add Comma To Numbers In Javascript (Thousands Separator)
July 9, 2024 - This tutorial will walk through how to add comma and thousands separator to numbers in Javascript. Free example code download included.
🌐
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.
🌐
Delft Stack
delftstack.com › home › howto › javascript › javascript add commas to number
How to Format Number With Commas in JavaScript | Delft Stack
February 2, 2024 - We will use the format() function attached to the object yielded by Intl.NumberFormat(). This function takes in the number and returns a comma-separated string.
🌐
W3Resource
w3resource.com › javascript-exercises › fundamental › javascript-fundamental-exercise-125.php
JavaScript fundamental (ES6 Syntax): Convert a float-point arithmetic to the Decimal mark form and It will make a comma separated string from a number - w3resource
Write a JavaScript program that converts float-point arithmetic to decimal form, and creates a comma separated string from a number. Use Number.prototype.toLocaleString() to convert the number to decimal mark format.
🌐
Reddit
reddit.com › r/javascript › how do i insert comma between numbers?
r/javascript on Reddit: How do I insert comma between numbers?
December 12, 2016 -

I'm having javascript do number calculations for me. I need to insert a comma between ever 3rd number. For instance, the number currently appears as $1234567.89 but I need it to appear as $1,234,567.89. How do I fix it? This my current code:

"$ " + (var1 + var2).toFixed(2)

Thanks!

*grammar

Top answer
1 of 3
2
u/zappsg 's recommendation is a lot better, but for the purpose of learning, here's one way you could do it with some comments explaining how it works: function formatNumber(num) { // If the number is less than zero, make a note of this var isNegative = num < 0; // Convert the number to a string with two decimal palces, // then split that string into an array of characters. If the // number was lower than zero, throw away the minus sign var tempNumArray = isNegative ? num.toFixed(2).split('').slice(1) : num.toFixed(2).split(''); // We're gonna keep track of the period so we know not to add commas after it var dotIndex = tempNumArray.indexOf('.'); // The number of digits to the left of the decimal point // is 3 less than the length of the array var integerCount = tempNumArray.length - 3; // Map over every digit in the array var formattedArray = tempNumArray.map(function(digit, index, arr) { // Check if we're in the whole digits var isBeforeDot = (index + 1) < dotIndex; // If we're in the whole digits, check if the number of whole digits still left to go % 3 is 0. // If it is, we need to add a comma, so we'll return the current digit plus a comma. if (isBeforeDot && (integerCount - (index + 1)) % 3 === 0) { return digit + ','; } else { // Otherwise we just return the digit. return digit; } // Join our newly mapped array back into a string }).join(''); // If our number was negative return it with a minus sign in front, // otherwise just return the number return isNegative ? '-' + formattedArray : formattedArray; } Then, to use it, you'd just do: "$ " + formatNumber(var1 + var2);
2 of 3
1
It's built into JavaScript already. By default it tries to detect the client's locale and uses this. You can force it, if you want. See here for details . var number = 1234567.89; var result = '$' + number.toLocaleString('en'); //force to comma as separator http://codepen.io/anon/pen/woYaep?editors=1010
🌐
HashBangCode
hashbangcode.com › article › format-numbers-commas-javascript
Format Numbers With Commas In JavaScript | #! code
I can now include this function into my JavaScript library and do this on the client side. The function works by using regular expressions to first split the string into whole number and decimal, before splitting the number by groups of three digits.