编程爱好者之家
$num = 20.6568; //第一种:利用round()对浮点数进行四舍五入 echo round($num,2); //20.66 //第二种:利用sprintf格式化字符串 推荐使用第二种 如果$num = 20 输出$num = 20.00 $format_num = sprintf("%.2f",$num); echo $format_num; //20.66 //第三种:利用千位分组来格式化数字的函数number_format() echo number_format($num, 2); //20.66 echo number_format($num, 2, '.', ''); //20.66