How to convert a string with zeros to number in JavaScript?

JavascriptWeb DevelopmentFront End TechnologyObject Oriented Programming

Let’s say the following is our string”

var stringValue="453.";

To convert the above string with zeroes to number, use parseInt() along with replace() −

var numberValue = parseInt(stringValue.replace(/\./gm, ''));


Following is the complete code −

var stringValue="453.";
var numberValue = parseInt(stringValue.replace(/\./gm, ''));
console.log("Original value="+stringValue)
console.log("After modification the value="+numberValue);

To run the above program, use the following command −

node fileName.js.

Here, my file name is demo239.js.


The output is as follows −

PS C:\Users\Amit\javascript-code> node demo239.js
Original value=453.
After modification the value=45300000000000
Updated on 03-Oct-2020 15:22:19