number_format ( float $number
[, int $decimals
= 0 ] ) : stringnumber_format ( float $number
, int $decimals
= 0 , string $dec_point
= "." , string $thousands_sep
= "," ) : string
如果只提供第一个参数,number
的小数部分会被去掉 并且每个千位分隔符都是英文小写逗号","
如果提供两个参数,number
将保留小数点后的位数到你设定的值,其余同楼上
如果提供了四个参数,number
将保留decimals
个长度的小数部分, 小数点被替换为dec_point
,千位分隔符替换为thousands_sep
<?php
$number = 1234.56;
// english notation (default)
$english_format_number = number_format($number);
// 1,235
// French notation
$nombre_format_francais = number_format($number, 2, ',', ' ');
// 1 234,56
$number = 1234.5678;
// english notation without thousands separator
$english_format_number = number_format($number, 2, '.', '');
// 1234.57
?>