I am trying to sum up the following numbers.
var number1= 12,000.00 ; var number2= 12,000.00;
I have tried this alert(number1+number2);
but it doesn't return any data.
Could you please help me to solve this problem?
Thanks
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) );
This won't work. Use accounting.js 's unformat
function to parse 12,000 as a string instead.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.