我想计算的价格不含税实时这样的:计算价格不含税没有给出确切的价格
价格包括taxe(priceTi)= 550
将TaxRate = 10 %
价格不含税(priceTe)应该= 500
的问题是,我得到priceTe = 499.99999999999994
$(document).on('keyup', "#priceTi", function() {
var priceTe = $('#priceTe');
var taxRate = $('#taxRate');
var priceTi = $('#priceTi');
if (taxRate.val() != "") {
value = this.value.replace(/,/g, '.');
var tax = parseFloat((taxRate.val()/100) + 1) ;
$('#priceTe').val(parseFloat(value)/tax) ;
return false;
}
});
欢迎即浮点数的快乐痛苦。你可以使用'toFixed()'来解决这个问题。 –
http://stackoverflow.com/questions/588004/is-floating-point-math-broken – epascarello