Possible en double:
Is JavaScript's Math broken?
Adding fractions number yields different result in PHPcalcul étrange en PHP
$grand_total = (float)$subtotal_email + (float)$delivery_email + (float)$fuel_surcharge_email - (float)$discount_coupon_email + (float)$texas_tax_email - (float)$cancel_fee_email - (float)$refund_email - (float)$refund_tax_email - (float)$coupon_tmp;
echo (float)$subtotal_email." + ".(float)$delivery_email." + ".(float)$fuel_surcharge_email." - ".(float)$discount_coupon_email." + ".(float)$texas_tax_email." - ".(float)$cancel_fee_email." - ".(float)$refund_email." - ".(float)$refund_tax_email." - ".(float)$coupon_tmp." = ".(float)$grand_total;
Quand je lance ci-dessus en php, je reçois la sortie suivante:
89.99 + 0 + 16.2 - 0 + 8.61 - 3 - 100 - 10 - 1.8 = -2.88657986403E-15
Mais si vous regardez LHS, il devrait être 0
, et cela se produit avec ou sans float .... une idée pourquoi?
[regardez ici] (http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html) – k102