programming-examples/js/Math/Currency math (add, subtract, multiply, division).js

11 lines
455 B
JavaScript
Raw Normal View History

2019-11-15 12:59:38 +01:00
var n1 = '$40.24';
var n2 = '$21.57';
var regp = /[^0-9.-]+/g;
console.log(parseFloat(n1.replace(regp, '')) + parseFloat(n2.replace(regp, '')));
console.log(parseFloat(n1.replace(regp, '')) - parseFloat(n2.replace(regp, '')));
console.log(parseFloat(n1.replace(regp, '')) * parseFloat(n2.replace(regp, '')));
console.log(parseFloat(n1.replace(regp, '')) / parseFloat(n2.replace(regp, '')));