您好,欢迎访问一九零五行业门户网

PHP round() 函数四舍五入php函数

php round() 函数四舍五入php函数 在php中round() 函数的使用是对浮点数进行四舍五入。 round(x,prec)
x,是要处理的浮点型数据
 prec,保存几位小数
提示和注释
注释:php 默认不能正确处理类似 12,300.2 的字符串。
注释:prec 参数是在 php 4 中被引入的。。
*/
//实例浮点数的截断函数,返回值仍为浮点数。
$foo   =   round(3.4);     //   $foo   ==   3.0  
  $foo   =   round(3.5);     //   $foo   ==   4.0  
  $foo   =   round(3.6);     //   $foo   ==   4.0  
  $foo   =   round(3.6,   0);     //   equivalent   with   above
$foo   =   round(1.95583,   2);     //   $foo   ==   1.96
$foo   =   round(1241757,   -3);     //   $foo   ==   1242000
//round实例二
echo(round(0.68));
echo(round(0.40));
echo(round(0.3));
echo(round(-3.30));
echo(round(-4.90));
/*
1
0
0
-3
-5
*/
//返回将 x 根据指定精度 prec (十进制小数点后数字的数目)进行四舍五入的结果。prec 也可以是负数或零(默认值
其它类似信息

推荐信息