问问题
11325 次
2 回答
8
The code in your question is invalid javascript. You can't have a ,
inside a numeric literal. You have to store it as a string, then parse it manually:
var number1 = '12,000.00';
var number2 = '12,000.00';
function parseCurrency( num ) {
return parseFloat( num.replace( /,/g, '') );
}
alert( parseCurrency(number1) + parseCurrency(number2) );
于 2012-08-29T03:58:49.057 回答
3
This won't work. Use accounting.js's unformat
function to parse 12,000 as a string instead.
于 2012-08-29T03:55:27.897 回答