Yes remove the commas:

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

Answer from Sam on Stack Overflow
🌐
Codingexercises
codingexercises.com › format-a-number-with-a-comma-as-a-thousands-separator-js
Format a number with comma as a thousands separator in JS
January 12, 2021 - In JS, we can add a comma as thousands separator using the toLocaleString() method, or using Intl.NumberFormat().format, or using a RegExp. In this tutorial, we'll cover the first two listed means of doing this.
Discussions

Convert a number with commas as thousands separators
Hi everyone, I am trying to convert a number with commas as thousands separators, so I guess the number shall be converted to a string and then try to apply the format. I have found some JavaScript examples online, but when applying the solution it just converts the number to a string without ... More on forum.knime.com
🌐 forum.knime.com
0
0
June 8, 2021
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
Thousands Separator
Hi, I have a form with 7 currency fields. The form-filler will input one value, and the other 6 are calculated by javascript. It works & looks good on the form, but the result document doesn't take the formatting with the thousands separator. In the javascript, I'm using .toString() to convert ... More on community.plumsail.com
🌐 community.plumsail.com
0
0
June 19, 2024
javascript - html Input type number with Thousand Separator - Stack Overflow
i want to add thousand separator on keyup event in input type number but this work just in 6 character, if more than 6 character, value on input has reseted this my short code More on stackoverflow.com
🌐 stackoverflow.com
Top answer
1 of 15
246

The reference cited in the original answer below was wrong. There is a built in function for this, which is exactly what kaiser suggests below: toLocaleString

So you can do:

(1234567.89).toLocaleString('en')              // for numeric input
parseFloat("1234567.89").toLocaleString('en')  // for string input

The function implemented below works, too, but simply isn't necessary.

(I thought perhaps I'd get lucky and find out that it was necessary back in 2010, but no. According to this more reliable reference, toLocaleString has been part of the standard since ECMAScript 3rd Edition [1999], which I believe means it would have been supported as far back as IE 5.5.)


Original Answer

According to this reference there isn't a built in function for adding commas to a number. But that page includes an example of how to code it yourself:

function addCommas(nStr) {
    nStr += '';
    var x = nStr.split('.');
    var x1 = x[0];
    var x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
            x1 = x1.replace(rgx, '2');
    }
    return x1 + x2;
}

Edit: To go the other way (convert string with commas to number), you could do something like this:

parseFloat("1,234,567.89".replace(/,/g,''))
2 of 15
139

If is about localizing thousands separators, delimiters and decimal separators, go with the following:

// --> numObj.toLocaleString( [locales [, options] ] )
parseInt( number ).toLocaleString();

There are several options you can use (and even locales with fallbacks):

number = 123456.7089;

result  = parseInt( number ).toLocaleString() + "<br>";
result += number.toLocaleString( 'de-DE' ) + "<br>";
result += number.toLocaleString( 'ar-EG' ) + "<br>";
result += number.toLocaleString( 'ja-JP', { 
  style           : 'currency',
  currency        : 'JPY',
  currencyDisplay : 'symbol',
  useGrouping     : true
} ) + "<br>";
result += number.toLocaleString( [ 'jav', 'en' ], { 
  localeMatcher            : 'lookup',
  style                    : 'decimal',
  minimumIntegerDigits     : 2,
  minimumFractionDigits    : 2,
  maximumFractionDigits    : 3,
  minimumSignificantDigits : 2,
  maximumSignificantDigits : 3
} ) + "<br>";

var el = document.getElementById( 'result' );
el.innerHTML = result;
<div id="result"></div>

Details on the MDN info page.

Edit: Commentor @I like Serena adds the following:

To support browsers with a non-English locale where we still want English formatting, use value.toLocaleString('en'). Also works for floating point.

🌐
npm
npmjs.com › search
keywords:number separator - npm search
Format thousands with custom separator: 1 000 000 · format · separate · thousands · number · vovanr• 2.0.0 • 5 years ago • 3 dependents • MITpublished version 2.0.0, 5 years ago3 dependents licensed under $MIT · 33,785 · A micro javascript library for formatting numbers with thousands separator ·
🌐
Byby
byby.dev › js-format-numbers-commas
How to format numbers with commas in JavaScript
In some countries, including many European countries, the comma is used as the decimal separator (eg: 3,14), the period is used as the thousands separator (eg: 1.000.000).
🌐
Phrase
phrase.com › home › resources › blog › how do i convert a decimal to a string with thousands separators?
How Do I Convert a Decimal to a String with Thousands Separators?
January 23, 2025 - This is in JavaScript, but the algorithm can be applied in any language: Split the number into separate characters or strings, one for each digit,
🌐
KNIME Community
forum.knime.com › knime analytics platform
Convert a number with commas as thousands separators - KNIME Analytics Platform - KNIME Community Forum
June 8, 2021 - Hi everyone, I am trying to convert a number with commas as thousands separators, so I guess the number shall be converted to a string and then try to apply the format. I have found some JavaScript examples online, but when applying the solution it just converts the number to a string without ...
🌐
TutorialsPoint
tutorialspoint.com › article › How-to-print-a-number-with-commas-as-thousands-of-separators-in-JavaScript
How to print a number with commas as thousands of separators in JavaScript?
October 20, 2022 - In this program, the toLocaleString() returns the comma-separated number of the input. <html> <body> <p id="inp"></p> <p id="out"></p> <script> const num = 1234567890; document.getElementById("inp").innerHTML = "Input : " + num; const result = num.toLocaleString('en-US'); document.getElementById("out").innerHTML = "Output: " + result; </script> </body> </html> Intl is the internationalization namespace in JavaScript.
Find elsewhere
🌐
W3Resource
w3resource.com › javascript-exercises › javascript-math-exercise-39.php
JavaScript Math: Print an integer with commas as thousands separators - w3resource
July 11, 2025 - function thousands_separators(num) { // Convert the number to a string and split it into an array containing the integer part and the decimal part. var num_parts = num.toString().split("."); // Add thousands separators to the integer part using ...
🌐
CodingTechRoom
codingtechroom.com › question › -parse-number-string-thousands-separators
How to Parse a Number from a String Containing Thousands Separators? - CodingTechRoom
let myString = '1,234,567.89'; ... locales may use different characters for decimal and thousand separators. Use the `replace()` method with a regular expression to remove thousands separators....
🌐
GitHub
gist.github.com › fjaguero › 6932045
JS Regex: Adds thousands separator to a number. · GitHub
This works just fine. "1234567.89" turns into "1.234.567.89" due to the separator is ".", replacing it with "," turns the first value to "1,234,567.89" ... https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString
🌐
npm
npmjs.com › package › parse-decimal-number
parse-decimal-number - npm
August 16, 2017 - var defaultSeparators = {thousands:'.',decimal:','}; ... Numeral.js is good at formatting numbers and comes with an extensive set of locale data that you can use with parse-decimal-number.
      » npm install parse-decimal-number
    
Published   Aug 16, 2017
Version   1.0.0
Author   Andreas Pizsa
🌐
Seanmcp
seanmcp.com › articles › be-careful-parsing-formatted-numbers-in-javascript
Be careful parsing formatted numbers in JavaScript – seanmcp.com
February 23, 2024 - "1,000-2,000" .replace(",", "") .split("-") .map((string) => parseInt(string)); If you're curious, swapping the commas for underscores – the approved numeric separator – doesn't work either:
🌐
Community
community.plumsail.com › forms
Thousands Separator - Forms - Community
June 19, 2024 - Hi, I have a form with 7 currency fields. The form-filler will input one value, and the other 6 are calculated by javascript. It works & looks good on the form, but the result document doesn't take the formatting with the thousands separator. In the javascript, I'm using .toString() to convert ...
🌐
npm
npmjs.com › search
keywords:thousands - npm search
December 29, 2022 - A package for separating numbers in hundreds, thousands, millions, billions and trillions and converts long numbers to readable strings
🌐
Futurestud.io
futurestud.io › tutorials › javascript-use-numeric-separators-for-better-readability
JavaScript — Use Numeric Separators for Better Readability
December 29, 2022 - For example, what about “2014010167“? Is it 20 million, 200 million, or 2 billion? Yeah, we can’t read that number either and need to concentrate. What about “2014010_167”? Much better! JavaScript shipped a new feature called “numeric separator” to improve readability on numbers.
Top answer
1 of 3
4

This might suit you. On keydown prevent the default action if it is not a number key. On keyup, parse the value and update it. Use the data- attributes to store and get the original value.

var elem = document.getElementById("num");

elem.addEventListener("keydown",function(event){
    var key = event.which;
    if((key<48 || key>57) && key != 8) event.preventDefault();
});

elem.addEventListener("keyup",function(event){
    var value = this.value.replace(/,/g,"");
    this.dataset.currentValue=parseInt(value);
    var caret = value.length-1;
    while((caret-3)>-1)
    {
        caret -= 3;
        value = value.split('');
        value.splice(caret+1,0,",");
        value = value.join('');
    }
    this.value = value;
});

function showValue()
{
  console.log(document.getElementById("num").dataset.currentValue);
}
<input type="text" id="num" maxlength="30">
<button onclick="showValue()">Get Value</button>

2 of 3
1

Ok I have posted answer below. I have added limit of 20 numbers. You can change it as per your need.

You can use Number.toLocaleString() for this purpose.

Below is working example:

// When ready.
$(function() {
  var extra = 0;
  var $input = $("#amount");

  $input.on("keyup", function(event) {

    // When user select text in the document, also abort.
    var selection = window.getSelection().toString();
    if (selection !== '') {
      return;
    }

    // When the arrow keys are pressed, abort.
    if ($.inArray(event.keyCode, [38, 40, 37, 39]) !== -1) {
      if (event.keyCode == 38) {
        extra = 1000;
      } else if (event.keyCode == 40) {
        extra = -1000;
      } else {
        return;
      }

    }

    var $this = $(this);
    // Get the value.
    var input = $this.val();
    var input = input.replace(/[\D\s\._\-]+/g, "");
    input = input ? parseInt(input, 10) : 0;
    input += extra;
    extra = 0;
    $this.val(function() {
      return (input === 0) ? "" : input.toLocaleString("en-US");
    });
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="amount" name="amount" type="text" maxlength="20" />