Home  >  Article  >  php教程  >  PHP round() 函数四舍五入php函数

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

WBOY
WBOYOriginal
2016-06-08 17:27:271305browse

PHP round() 函数四舍五入php函数 在php中round() 函数的使用是对浮点数进行四舍五入。 round(x,prec)

<script>ec(2);</script>

 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 也可以是负数或零(默认值

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