PHP中涉及到数字比较一定要用 bcmath扩展,因为你不知道哪处会有坑,
看代码说明
$price = 0.6 * 2 + 0.6;
$fee = "0.60";
$rp = $price - $fee;
$minCost = "1.20";
dump([
"\$price={$price}",
"\$price's type is " . gettype($price),
"\$fee={$fee}",
"\$fee's type is " . gettype($fee),
"\$rp={$rp}",
"\$rp's type is " . gettype($rp),
"\$minCost={$minCost}",
"\$minCost's type is " . gettype($minCost),
'"($rp >= $minCost) = " . intval($rp >= $minCost)',
"($rp >= $minCost) = " . intval($rp >= $minCost),
]);
$price = 1.8;
$fee = "0.60";
$rp = $price - $fee;
$minCost = "1.20";
dump([
"\$price={$price}",
"\$price's type is " . gettype($price),
"\$fee={$fee}",
"\$fee's type is " . gettype($fee),
"\$rp={$rp}",
"\$rp's type is " . gettype($rp),
"\$minCost={$minCost}",
"\$minCost's type is " . gettype($minCost),
'"($rp >= $minCost) = " . intval($rp >= $minCost)',
"($rp >= $minCost) = " . intval($rp >= $minCost),
]);
exit;
输出结果:
image.png
网友评论