function getSubTotal(tr){ var tds = tr.cells; var price = parseFloat(tds[2].innerHTML) var count = parseInt(tr.getElementsByTagName('input')[1].value) var SubTotal = parseFloat(count*price) tds[4].innerHTML = SubTotal.toFixed(2) }
所以我在后面加了.toFixed(2),无论后面怎么加都不会出问题了,……这算是自问自答吗?
var SubTotal = parseFloat(price*count);
改成var SubTotal = parseFloat(price*count).toFixed(2); 就可以了