I'm working on a simple subtraction problem, but unfortunately it keeps returning NaN
Here is the function
function subtraction(a, b) {
var regexp = /[$][,]/g;
a = a.replace(regexp, "");
b = b.replace(regexp, "");
var _a = parseFloat(a);
var _b = parseFloat(b);
return _a - _b;
}
And here is how I'm calling it.
txtGoodWill.value = subtraction(txtSellingPrice.value, txtBalanceSheet.value);
The numbers that get submitted to the function are ONLY Currency (IE: $2,000
or $20
, etc)
Now I know that I cannot subtract numbers with a $
or a ,
, but I can't for the life of me figure out why they are getting evaluated in the equasion.