日期:2014-05-17  浏览次数:20447 次

PHP_保留两位小数并且四舍五入_保留两位小数并且不四舍五入
php保留两位小数并且四舍五入
$num = 123213.666666;
echo sprintf("%.2f", $num);



php保留两位小数并且不四舍五入
$num = 123213.666666;
echo sprintf("%.2f",substr(sprintf("%.3f", $num), 0, -2));


php进一法取整
echo ceil(4.3);    // 5
echo ceil(9.999);  // 10


php舍去法,取整数
echo floor(4.3);   // 4
echo floor(9.999); // 9
1 楼 bardo 2011-03-28  
echo round(123213.666666,2);
echo number_format((ceil(123213.666666 * 100))/100,2,'.','');
substr效率很差。这样做是不是更简单?
建议多看看手册吧。
2 楼 kk48323201 2011-03-28  
bardo 写道
echo round(123213.666666,2);
echo number_format((ceil(123213.666666 * 100))/100,2,'.','');
substr效率很差。这样做是不是更简单?
建议多看看手册吧。

谢谢指教..