var totalPrice = 0; function addGoods(price) { totalPrice = addPrice(totalPrice, price); getPrice(totalPrice); } function getPrice(price) { var f = parseFloat(price); if (isNaN(f)) { return false; } var f = Math.round(price*100)/100; var s = f.toString(); var rs = s.indexOf('.'); if (rs < 0) { rs = s.length; s += '.'; } while (s.length <= rs + 2) { s += '0'; } document.getElementById('MM-Price-span').innerText='$'+s; } function addPrice(arg1,arg2) { return parseInt(arg1)+parseInt(arg2); }