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