var a='1,125';
a=a.replace(/\,/g,''); // 1125, but a string, so convert it to number
a=parseInt(a,10);

Hope it helps.

Answer from web-nomad on Stack Overflow
🌐
GitHub
gist.github.com › 2187257
javascript: remove commas from string of numbers · GitHub
javascript: remove commas from string of numbers. GitHub Gist: instantly share code, notes, and snippets.
Discussions

javascript - remove comma separation from the specific number from JS - Stack Overflow
I want to remove comma separation from the specific number but i want decimal places and i wrote a regular expression for that, when i pass a number with decimal places it is ok. var num = '12,312... More on stackoverflow.com
🌐 stackoverflow.com
Removing commas in a string
Hey guys, i have a basic js question here… how can i remove commas in a string and replace them with a space. let myString = 'hello,this,is,a,difficult,to,read,sentence'; More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
1
0
September 18, 2019
javascript - How do you remove the comma from a number? - Stack Overflow
I have script that works fine until the shopping cart hits $1,000 or more then stops working. So I basically need a code that will remove the comma from this statement below when the cart hits 1,00... More on stackoverflow.com
🌐 stackoverflow.com
Remove commas from the string using JavaScript - Stack Overflow
I want to remove commas from the string and calculate those amount using JavaScript. For example, I have those two values: 100,000.00 500,000.00 Now I want to remove commas from those string an... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Reddit
reddit.com › r/learnjavascript › remove comma from number in array.
r/learnjavascript on Reddit: Remove comma from number in array.
March 30, 2022 -

Hi all, I'm trying to remove commas from my numbers that are in an array :

I know the method '.toFixed(2)' but I'm having trouble applying it in a .map

This is what I did:

And this is what I get :

Unfortunately I added the two values ​​so I don't get an array anymore.

What would be the right way to find an array like I had but without a comma?
How do I merge them into my array? 🙂

🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Removing commas in a string - JavaScript - The freeCodeCamp Forum
September 18, 2019 - Hey guys, i have a basic js question here… how can i remove commas in a string and replace them with a space. let myString = 'hello,this,is,a,difficult,to,read,sentence';
🌐
YouTube
youtube.com › dritalconnect
How to remove comma from number from string in JavaScript - YouTube
How to remove comma from number from string in JavaScript
Published   May 30, 2022
Views   910
🌐
Laserfiche Answers
answers.laserfiche.com › questions › 66574 › How-to-Remove--From-Number-Fields
How to Remove ',' From Number Fields? - Laserfiche Answers
In Forms 9.2 I have noticed that number fields automatically add a ',' to the values in them. Is there a way to change this? We have number fields that are used for zip codes and having a ',' in the zip code is not ideal. ... Since this is IE specific behavior, you can workaround this by using the following javascript to remove commas from the input.
Find elsewhere
🌐
Medium
frontendinterviewquestions.medium.com › how-to-remove-comma-from-string-in-javascript-21c88f166c28
How to remove comma from string in JavaScript | by Pravin M | Medium
March 13, 2024 - let myString = "This, is, a, string, with, commas."; let newString = myString.replace(/,/g, ""); console.log(newString); // Output: This is a string with commas.
Top answer
1 of 3
239

To remove the commas, you'll need to use replace on the string. To convert to a float so you can do the maths, you'll need parseFloat:

var total = parseFloat('100,000.00'.replace(/,/g, '')) +
            parseFloat('500,000.00'.replace(/,/g, ''));
2 of 3
7

Related answer, but if you want to run clean up a user inputting values into a form, here's what you can do:

const numFormatter = new Intl.NumberFormat('en-US', {
  style: "decimal",
  maximumFractionDigits: 2
})

// Good Inputs
parseFloat(numFormatter.format('1234').replace(/,/g,"")) // 1234
parseFloat(numFormatter.format('123').replace(/,/g,"")) // 123

// 3rd decimal place rounds to nearest
parseFloat(numFormatter.format('1234.233').replace(/,/g,"")); // 1234.23
parseFloat(numFormatter.format('1234.239').replace(/,/g,"")); // 1234.24

// Bad Inputs
parseFloat(numFormatter.format('1234.233a').replace(/,/g,"")); // NaN
parseFloat(numFormatter.format('$1234.23').replace(/,/g,"")); // NaN

// Edge Cases
parseFloat(numFormatter.format(true).replace(/,/g,"")) // 1
parseFloat(numFormatter.format(false).replace(/,/g,"")) // 0
parseFloat(numFormatter.format(NaN).replace(/,/g,"")) // NaN

Use the international date local via format. This cleans up any bad inputs, if there is one it returns a string of NaN you can check for. There's no way currently of removing commas as part of the locale (as of 10/12/19), so you can use a regex command to remove commas using replace.

ParseFloat converts the this type definition from string to number

If you use React, this is what your calculate function could look like:

updateCalculationInput = (e) => {
    let value;
    value = numFormatter.format(e.target.value); // 123,456.78 - 3rd decimal rounds to nearest number as expected
    if(value === 'NaN') return; // locale returns string of NaN if fail
    value = value.replace(/,/g, ""); // remove commas
    value = parseFloat(value); // now parse to float should always be clean input

    // Do the actual math and setState calls here
}
🌐
Snipplr
snipplr.com › view › 73098 › addingremove-commas-in-digits
Adding/remove commas in digits - JavaScript Snipplr Social Repository
December 6, 2013 - Ex: 1,000 Useful for grabbing input values to format then display, remove the comma and convert back to number to do math.
🌐
Online Tools
onlinetools.com › integer › remove-commas-from-an-integer
Remove Commas from an Integer – Online Integer Tools
This browser-based program quickly removes comma symbols that are often used as thousands separators. For example, if you give it the integer 23,456,789 with commas, then you'll get back the integer 23456789 without commas. It also works with Indian integers such as 1,23,45,678, which will get converted to 12345678. Created by math nerds from team Browserling.
🌐
thisPointer
thispointer.com › home › javascript › remove comma from string in javascript
Remove comma from string in javascript - thisPointer
August 13, 2021 - Here the above code uses the replaceAll() method to replace all the occurrences of comma (,). The comma (‘,’) is passed as the first argument, and replacement is passed as the second argument, nothing (”) in our case.
🌐
Pipedream
pipedream.com › help
How to Remove Dots and Commas from a Number Using a Formatting Function in the Flow? - Help - Pipedream
March 1, 2024 - This topic was automatically generated from Slack. You can find the original thread here. How do i remove any . or , from a number? i want to keep any digit thats a number and remove anything else. Is there a formatting…
🌐
Stack Overflow
stackoverflow.com › questions › 62309857 › how-to-remove-numbers-after-a-comma
javascript - How to remove numbers after a comma? - Stack Overflow
I have strings like this: 300.123,25 and after the comma I want to have always one digit. ... value = value.toString().replace(/[^0-9\,]/g, "") value = value.replace(/\B(?=(\d{3})+(?!\d))/g, ".") I removed letters and other symbols.
🌐
EncodedNA
encodedna.com › javascript › how-to-remove-commas-from-array-in-javascript.htm
How to Remove Commas from Array in JavaScript
You can use the join() method in JavaScript to remove commas from an array. The comma delimiter in an array works as the separator.
🌐
Delft Stack
delftstack.com › home › howto › javascript › remove commas from string javascript
How to Remove Commas From String in JavaScript | Delft Stack
February 2, 2024 - In this tutorial, we will teach you how to remove commas from a string. We'll use the replace method, join method and lodash replace() method. To perform arithmetic computations, we'll use the parseFloat function on the resulting string.
🌐
Java2Blog
java2blog.com › home › core java › remove comma from string in javascript
Remove Comma from String in JavaScript - Java2Blog
May 24, 2022 - g denotes global replacement here. It is flag at end of regex which depicts that we want to remove all the commas not only first one.
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-remove-all-commas-from-string
Remove/Replace all Commas from a String in JavaScript | bobbyhadz
The replaceAll() method will remove all commas from the string by replacing them with empty strings.