Skip to content

Javascript parseFloat thousand comma | Example code

  • by

If you want parse a number (float number) string with commas thousand separators into a number by removing the commas, and then use the + operator to do the conversion.

const num = +'123,456,789'.replace(/,/g, '');
console.log(num)

You can do it with parseFloat method and replace method.

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

Javascript parseFloat thousand comma

Simple example code. Where replace with /,/g to match all commas and replace them all with empty strings.

And then we use the unary + operator to convert the string without the commas to a number.

 <!DOCTYPE html>
 <html>
 <body>

  <script>
    var str = '123,456,789';
    const num = +str.replace(/,/g, '');

    console.log(num);
    console.log(typeof(num));
  </script>

</body>
</html> 

Output:

Javascript parseFloat thousand comma

Make a float to have comma-separated Javascript

var n = 34523453.345
n.toLocaleString()
 // "34,523,453.345"

Do comment if you have any doubts or suggestions on this JS parseFlaot method code.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Your email address will not be published. Required fields are marked *