主页 M

php格式化数字输出,输出形如4,999.95

2021-10-22 网页编程网 网页编程网

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

阅读原文
阅读 2846
123 显示电脑版