<?php
$num = 4999.944444;
$formattedNum = number_format($num).PHP_EOL;
echo $formattedNum;
$formattedNum = number_format($num, 2);
echo $formattedNum;
5,000
4,999.94
<?php
$num = 4999.945444;
$formattedNum = number_format($num).PHP_EOL;
echo $formattedNum;
$formattedNum = number_format($num, 2);
echo $formattedNum;
5,000
4,999.95
由此可见,number_format是4舍5入的策略。
<?php
$num = 4999.944444;
$formattedNum = number_format($num).PHP_EOL;
echo $formattedNum;
$formattedNum = number_format($num, 1);
echo $formattedNum;
5,000
4,999.9
<?php
$num = 4999.954444;
$formattedNum = number_format($num).PHP_EOL;
echo $formattedNum;
$formattedNum = number_format($num, 1);
echo $formattedNum;
5,000
5,000.0
它会将留的小数位后面一位作为四舍五入的标准。
原文地址:https://www.cnblogs.com/jiqing9006/p/10625433.html
时间: 2024-10-14 01:00:03