我有这个
$example = "1234567"
$subtotal = number_format($example, 2, '.', '');
$subtotal 的返回值是 "1234567.00"
如何修改$subtotal的定义,让它变成这样"1,234,567.00"
最佳答案
下面会输出1,234,567.00
$example = "1234567";
$subtotal = number_format($example, 2, '.', ',');
echo $subtotal;
语法
string number_format ( float $number , int $decimals = 0 , string $dec_point = '.' , string $thousands_sep = ',' )
但我建议您使用 money_format,它将数字格式化为货币字符串
关于php - 在 php 中添加逗号作为千位分隔符和 float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17780653/