php 保留小数点后两位

  • Post author:
  • Post category:php

方法1 number_format 以千位分隔符方式格式化一个数字

$draw = number_format(100/3,2);
        echo $draw;

结果

33.33

方法2 sprintf 格式化字符串

echo sprintf("%.2f",100/3);

方法3 round 对浮点数四舍五入

echo round(100/3,2);

参考源