【发布时间】:2011-01-12 15:56:18
【问题描述】:
我知道我可以编写一个自定义函数来执行此操作,但感觉这是一个应该已经存在(内置)的函数。
所以,我只是想添加空格以使其更易于阅读:
1200 将变为:1 200 10000 将变为:10 000 150000 将变为:150 000 等等……
是否有一个函数可以将一个字符串/字符“弹出”到另一个字符串的指定位置?
【问题讨论】:
我知道我可以编写一个自定义函数来执行此操作,但感觉这是一个应该已经存在(内置)的函数。
所以,我只是想添加空格以使其更易于阅读:
1200 将变为:1 200 10000 将变为:10 000 150000 将变为:150 000 等等……
是否有一个函数可以将一个字符串/字符“弹出”到另一个字符串的指定位置?
【问题讨论】:
您只是在格式化数字吗? number_format() 可以接受任何类型的分隔符:
$formatted = number_format(1200, 0, '.', ' '); // "1 200"
1 2 3
1. # of decimal places
2. decimal place character (not inserted, since we've specified 0 decimals)
3. thousands separator (space, in this case)
【讨论】: