格式数字:
<?php
echo number_format("1000000")."<br>";
echo number_format("1000000",2)."<br>";
echo number_format("1000000",2,",",".");
?>
亲自试一试 »
number_format() 函数格式化一个以千为单位的数字。
笔记:此函数支持一个、两个或四个参数(不是三个)。
number_format(
number,decimals,decimalpoint,separator)
Parameter | Description |
---|---|
number | Required. The number to be formatted. If no other parameters are set, the number will be formatted without decimals and with comma (,) as the thousands separator. |
decimals | Optional. Specifies how many decimals. If this parameter is set, the number will be formatted with a dot (.) as decimal point |
decimalpoint | Optional. Specifies what string to use for decimal point |
separator | Optional. Specifies what string to use for thousands separator. Only the first character of separator is used. For example, "xxx" will give the same output as "x" Note: If this parameter is given, all other parameters are required as well |
返回值: | 返回格式化的数字 |
---|---|
PHP 版本: | 4+ |
变更日志: | 从 PHP 5.4 开始,该函数支持参数中包含多个字节小数点和分隔器。旧版本中仅使用每个分隔符的第一个字节。 |
您想要返回价格:一个参数将对数字进行四舍五入(其格式将不带小数)。两个参数应该给出您想要的结果:
<?php
$num = 1999.9;
$formattedNum = number_format($num)."<br>";
echo $formattedNum;
$formattedNum = number_format($num, 2);
echo $formattedNum;
?>
亲自试一试 »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!