I am having difficulties with a small math calculation.
I have a string from a form field which I need to convert to a number so I can multiply two fields together (it's a cost and qty field that then sets my total cost line).
The issue I am having is sometimes the number is a solid number (100, 150, 3), sometimes it has commas and sometimes it has decimals.
I have a .replace
to replace all the commas with nothing to assist with this issue and it works well.
It works great when I parseInt(var_name)
except it strips off my decimal points. I don't want rounding since it's actually part of a purchasing script.
How would I change my two string fields to a numeric field?
var num1 = '100.00';
var num2 = '200,000.51';
alert(num1 X num2); // 20,000,051.00