number_format 以千位分隔符方式格式化一个数字 &reftitle.description; stringnumber_format floatnum intdecimals0 stringnulldecimal_separator"." stringnullthousands_separator"," 使用四舍五入的规则,将数字格式化为千位分组和小数位(可选)。 &reftitle.parameters; num 要格式化的数字。 decimals 设置小数位数。如果为 0,则从返回值中忽略 decimal_separator。自 PHP 8.3.0 起,当值为负数时,num 将四舍五入为小数点前的有效数字 decimals。在 PHP 8.3.0 之前,负值将被忽略并与 0 一样处理。 decimal_separator 指定小数点的分隔符。 thousands_separator 设置千位分隔符。 &reftitle.returnvalues; num 的格式化版本。 &reftitle.changelog; &Version; &Description; 8.3.0 新增对 decimals 负值的处理。 8.0.0 在此版本之前,number_format 接受一个、两个或四个参数(不会是三个)。 7.2.0 number_format 现在再也不会返回 -0,之前 num-0.01 的情况下可以返回 -0 &reftitle.examples; <function>number_format</function> 示例 例如,法语计数通常使用两位小数,逗号(“,”)作为小数分隔符,空格(“ ”)作为千位分隔符。以下示例展示了格式化数字的各种方法: ]]> <parameter>decimals</parameter> 为负值 自 PHP 8.3.0 起,使用 decimals 的负值来对小数点前的有效数字的位数进行四舍五入。 ]]> &example.outputs; &reftitle.seealso; money_format sprintf printf sscanf