1.例1
$num = 4999.944444;
echo number_format($num).PHP_EOL;
5,000
echo number_format($num, 2);
4,999.94
2.例2
$num = 4999.945444;
echo number_format($num).PHP_EOL;
5,000
echo number_format($num, 2);
4,999.95
number_format是4舍5入的策略。将留的小数位后面一位作为四舍五入的标准。
3.例3
$num = 4999.944444;
echo number_format($num).PHP_EOL;
5,000
echo number_format($num, 1);
4,999.9
4.例4
$num = 4999.954444;
echo number_format($num).PHP_EOL;
5,000
echo number_format($num, 1);
5,000.0