我正在使用javascript绑定到某些复选框,并且toFixed(2)没有舍入。有什么想法为什么不四舍五入吗?例如,如果数字为,859.385则仅显示859.38而不是859.39。
我也读过,toFixed可以根据您使用的浏览器而不同地进行舍入,任何人都知道解决此问题的方法,以便我的javascript计算与我的php计算匹配?
var standardprice = parseFloat($('#hsprice_'+this.id.split('_')[1]).val());
var price = parseFloat($('#hprice_'+this.id.split('_')[1]).val());
var discount = parseFloat($('#hdiscount_'+this.id.split('_')[1]).val());
var deposit = parseFloat($('#hdeposit_'+this.id.split('_')[1]).val());
var currSprice = parseFloat($('#hTotalSprice').val());
var currPrice = parseFloat($('#hTotalPrice').val());
var currDiscount = parseFloat($('#hTotalDiscount').val());
var currDeposit = parseFloat($('#hTotalDeposit').val());
currSprice += standardprice;
currPrice += price;
currDiscount += discount;
currDeposit += deposit;
$('#lblTotalSprice').text('$'+addCommas(currSprice.toFixed(2)));
$('#lblTotalPrice').text('$'+addCommas(currPrice.toFixed(2)));
$('#lblTotalDiscount').text('$'+addCommas(currDiscount.toFixed(2)));
$('#lblTotalDeposit').text('$'+addCommas(currDeposit.toFixed(2)));
$('#hTotalSprice').val(currSprice.toFixed(2));
$('#hTotalPrice').val(currPrice.toFixed(2));
$('#hTotalDiscount').val(currDiscount.toFixed(2));
$('#hTotalDeposit').val(currDeposit.toFixed(2));
开心每一天1111
不负相思意
相关分类