我有一个SQL值& PHP的问题。 我正在做2请求,一个将值添加到我的SQL和另一个减去这个结果。SQL浮点值不= 0
这就是:
$totaux = $montant_actuel + ($nbre_dej * $prix_dejeuner) + ($nbre_din * $prix_diner) + ($nbre_soir_etape * $prix_etape);
当我这样做,它等于:
sum = 0 + (15.8*1) + (15.8*1) + (57.8*0)
所以我必须:31.6
但是,当我试图要做:
$totaux = $montant_actuel - ($nbre_dej * $prix_dejeuner) - ($nbre_din * $prix_diner) - ($nbre_soir_etape * $prix_etape);
sum = 31.6 - (15.8*1) - (15.8*1) - (57.8*0)
然后,当我将其插入到我的数据库,我有这样的记录:的0.0000000000000142109而不是0
我不明白为什么会这样。
你应该阅读[什么每个程序员应该知道浮点运算(HTTP://浮点贵。 de /) – 2013-06-24 10:10:01
http://stackoverflow.com/questions/3726721/php-math-precision/3726761#3726761 –