format()php,PHP函数补完:number_format()

number_format() 函数通过千位分组来格式化数字。

先来看看程序例子吧。

$num = 500000;

echo number_format($num);

// 500,000

echo number_format($num, 2);

// 500,000.00

echo number_format($num, 3, ".", ",");

// 500,000.000

?>

用法如下:

number_format(number,decimals,decimalpoint,separator)

参数描述

number必需。要格式化的数字。如果未设置其他参数,则数字会被格式化为不带小数点且以逗号 (,) 作为分隔符。

decimals可选。规定多少个小数。如果设置了该参数,则使用点号 (.) 作为小数点来格式化数字。

decimalpoint可选。规定用作小数点的字符串。

separator可选。规定用作千位分隔符的字符串。仅使用该参数的第一个字符。比如 "xyz" 仅输出 "x"。注释:如果设置了该参数,那么所有其他参数都是必需的。

该函数支持一个、两个或四个参数(不是三个)。

再来个详细的例子吧:

$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 seperator

$english_format_number = number_format($number, 2, '.', '');

// 1234.57

?>

延伸阅读

此文章所在专题列表如下:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值