Home > Backend Development > PHP Tutorial > php里 的 四舍五入_PHP

php里 的 四舍五入_PHP

WBOY
Release: 2016-06-01 12:34:51
Original
955 people have browsed it

比如我有0.10456,要变成10.5%?

round
(PHP 3, PHP 4 )
round -- 对浮点数进行四舍五入
说明
float round ( float val [, int precision])
返回将 val 根据指定精度 precision(十进制小数点后数字的数目)进行四舍五入的结果。precision 也可以是负数或零(默认值)。
注意
PHP 默认不能正确处理类似 "12,300.2" 的字符串。见字符串转换为数值。

echo round(3.4); // 3
echo round(3.5); // 4
echo round(3.6); // 4
echo round(3.6, 0); // 4
echo round(1.95583, 2); // 1.96
echo round(1241757, -3); // 1242000

注: precision 参数仅在 PHP 4 中可用。

echo round(0.10456*100,1);

$num = 0.10456;
echo round(($num*100),1)."%";
?>

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template