php 保留小数的几种方式


  $num = 10.45678; 

   //第一种:利用round()对浮点数进行四舍五入
   echo round ( $num ,2); //10.46
    
   //第二种:利用sprintf格式化字符串
   $format_num = sprintf( "%.2f" , $num );
   echo $format_num ; //10.46
    
   //第三种:利用千位分组来格式化数字的函数number_format()
   echo number_format( $num , 2); //10.46
   //或者如下
   echo number_format( $num , 2, '.' , '' ); //10/46


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM