这是我的 javascript 代码:
var dsum = 0.0;
$.each($("#Report tbody tr"), function () {
var x = 0.0;
if ($(this).find("td:eq(3) div").html() != " ")
x = parseFloat($(this).find("td:eq(3) div").html().replace(/,/g, ""));
dsum += x;
});
var csum = 0.0;
$.each($("#Report tbody tr"), function () {
var x = 0.0;
if ($(this).find("td:eq(4) div").html() != " ")
x = parseFloat($(this).find("td:eq(4) div").html().replace(/,/g, ""));
csum += x;
});
var lastEvenRow=$("#Report").find("tr:last").hasClass('erow');
$("<tr id='LastRow'><td colspan='3' style='border-top: 1px solid #DDDDDD;'><div style='padding:5px;text-align:right;'>Total :</div></td><td style='text-align:center;height:22px;border-top: 1px solid #DDDDDD;'><div style='padding:5px;'>" + dsum.toString(10).replace( /(\d)(?=(\d\d\d)+(?!\d))/g , "$1,") + "</div></td><td style='text-align:center;border-top: 1px solid #DDDDDD;'><div style='padding:5px;'>" + csum.toString(10).replace( /(\d)(?=(\d\d\d)+(?!\d))/g , "$1,") + "</div></td><td style='text-align:center;border-top: 0px solid #DDDDDD;'><div style='padding:5px;border-top: 1px solid #DDDDDD;'>" + (dsum > csum ? (dsum - csum).toString(10).replace( /(\d)(?=(\d\d\d)+(?!\d))/g , "$1,") : " ") + "</div></td><td style='text-align:center;'><div style='padding:5px;'>" + (csum >= dsum ? (csum - dsum).toString(10).replace( /(\d)(?=(\d\d\d)+(?!\d))/g , "$1,") : " ") + "</div></td></tr>").appendTo("#Report tbody");
if(lastEvenRow==false)
$("#LastRow").addClass("erow");
正如我在图片中提到的,我认为结果一定是 104,889.01 但是,如您所见,这是不正确的值
有没有人可以帮助我?抱歉我的英语语法不好(我是英语新手)
更新1:
1318114.01 - 1213225 必须是 104889.01 ,那么为什么 javascript 返回 104889.01000000001 呢?!!