Skip to content

JavaScript parseFloat comma | Example code

  • by

Do a replacement first to convert String with Dot or Comma as a decimal separator to number using parseFloat method in JavaScript.

JavaScript parseFloat comma

Simple example code.

 <!DOCTYPE html>
 <html>
 <body>

  <script>
    var str = '110 000,23';
    var res = parseFloat(str.replace(',','.').replace(' ',''));

    console.log(res)
  </script>

</body>
</html> 

Output:

JavaScript parseFloat comma

JavaScript parse float is ignoring the decimals after my comma

JavaScript’s parseFloat doesn’t take a locale parameter. So you will have to replace , with .

parseFloat('0,04'.replace(/,/, '.')); // 0.04

Do comment if you have any doubts or suggestions on this JS parseFloat topic.

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

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading