And*_*Liu 15 php comma number-formatting
我有这个
$example = "1234567"
$subtotal = number_format($example, 2, '.', '');
Run Code Online (Sandbox Code Playgroud)
$ subtotal的返回是"1234567.00"
如何修改$ subtotal的定义,使它像这样"1,234,567.00"
Tec*_*hie 31
下面会输出 1,234,567.00
$example = "1234567";
$subtotal = number_format($example, 2, '.', ',');
echo $subtotal;
Run Code Online (Sandbox Code Playgroud)
句法
string number_format ( float $number , int $decimals = 0 , string $dec_point = '.' , string $thousands_sep = ',' )
Run Code Online (Sandbox Code Playgroud)
但我建议你使用money_format,它会将数字格式化为货币字符串