This question already has answers here:
Problems with JavaScript “parseInt()” decimal string
                                
                                    (5个答案)
                                
                        
                                去年关闭。
            
                    
即时通讯试图计算货币,但当我尝试计算仅第一个数字(1.25 $ + 1.25 $返回2 $)时,这是我所做的代码

var table = document.getElementById("table"), sumVal = 0;

for (var i = 1; i < table.rows.length; i++)
{
    sumVal = sumVal + parseInt(table.rows[i].cells[3].innerHTML);
}

document.getElementById("val").innerHTML =  +sumVal  + "€";
console.log(sumVal);


我应该添加或编辑什么,以便我可以计算该行的整个值并返回2美元和50美分

最佳答案

parseInt替换为parseFloat

09-16 02:55