PHP round() 函数

定义和用法

round() 函数对浮点数进行四舍五入。

语法

round(x,prec)
参数 描述
x 可选。规定要舍入的数字。
prec 可选。规定小数点后的位数。

说明

返回将 x 根据指定精度 prec (十进制小数点后数字的数目)进行四舍五入的结果。prec 也可以是负数或零(默认值)。

提示和注释

注释:PHP 默认不能正确处理类似 "12,300.2" 的字符串。

注释:prec 参数是在 PHP 4 中被引入的。。

实例

<?php
echo(round(0.60));
echo(round(0.50));
echo(round(0.49));
echo(round(-4.40));
echo(round(-4.60));
?>

输出:

1
1
0
-4
-5