round -- 对浮点数进行四舍五入
例子:
<?php
echo round(3.4); // 3
echo round(3.6); // 4
echo round(3.6, 0); // 4
echo round(1.95583, 2); // 1.96
echo round(1241757, -3); // 1242000
echo round(5.055, 2); // 5.06
?>
ceil -- 进一法取整
例子:
<?php
echo ceil(4.3); // 5
echo ceil(9.999); // 10
?>
floor -- 舍去法取整,跟ceil刚刚相反
例子:
<?php
echo floor(4.3); // 4
echo floor(9.999); // 9
?>
number_format -- 格式化数字为千分位
<?php
$number = 1234;
// english notation (default)
$english_format_number = number_format($number);
echo "First:".$english_format_number."<br />";
// French notation
$nombre_format_francais = number_format($number, 2, ',', ' ');
echo "Second:".$nombre_format_francais."<br />";
// French notation
$number = 1234.564;
$nombre_format_francais = number_format($number, 2, ',', ' ');
echo "Third:".$nombre_format_francais."<br />";
$number = 1234.5678;
// english notation without thousands seperator
$english_format_number = number_format($number, 2, '.', '');
echo "Forth:".$english_format_number."<br />";
?>
显示结果最终如下:First:1,234
Second:1234,00
Third:1234,56
Forth:1234.57