Home  >  Article  >  Backend Development  >  PHP_保存两位小数并且四舍五入_保留两位小数并且不四舍五入

PHP_保存两位小数并且四舍五入_保留两位小数并且不四舍五入

WBOY
WBOYOriginal
2016-06-13 11:01:441179browse

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);    // 5echo ceil(9.999);  // 10


php舍去法,取整数
echo floor(4.3);   // 4echo 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效率很差。这样做是不是更简单?
建议多看看手册吧。
谢谢指教..
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn