How to convert a currency string to a double with jQuery or JavaScript?

JavascriptWeb DevelopmentFront End TechnologyObject Oriented Programming

To convert a currency key, use the replace() and within that set REGEX.

Example

Following is the code −

var euroCurrenyValue = "€55,600.35";
var result = Number(euroCurrenyValue.replace(/[^0-9.-]+/g,""));
console.log(result);
var dollarCurrenyValue = "$645,345.50";
var result1 = Number(dollarCurrenyValue.replace(/[^0-9.-]+/g,""));
console.log(result1);

To run the above program, you need to use the below command −

node fileName.js.

Here, my file name is demo324.js

Output

This will produce the following output −

PS C:\Users\Amit\javascript-code> node demo324.js
55600.35
645345.5
raja
Published on 27-Oct-2020 14:31:58
Advertisements