先看个例子
<?php
$user_money = round('9.12'*100);
echo ('9.12'*100)."\r\n";
//舍去法取整
echo (floor('9.12'*100)."\r\n");
//四舍五入
echo (round('9.12'*100)."\r\n");
$fee = 912;
if($fee > $user_money)
{
echo ($fee - $user_money);
echo ($fee.' '.$user_money);
}
?>
这里9.12*100以后得到的结果是912。但是在用舍去法取整后得到的是911.说明内部储存没有使用912来储存应该是911.xxxx
经过四舍五入以后得到912,
在这里下面的对比可以看出在没有使用round()方法进行四舍五入法取整前,$fee>$user_money成立,
为了避免这个坑,建议在float取整的过程中要用round方法进行转换一下,