PHP保存两位小数的几种要领

$num = 10.4567; //第一种:操作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

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wsdpgf.html