开发者

php formatting numbers?

I would like to format numbers, so numbers woul format like this:

1=1
10=10
100=100
1000开发者_StackOverflow=1,000
10000=10,000
100000=100,000
1000000=1,000,000

I think it can be done with number_format(), but right now I`m having a problem, so if the number is 35679 it shows 35,679,000.


If you want 35679 to show up as 35,679:

number_format(35679,0,'',',');

First parameter is the input number.
Second is the amount of decimals.
Third is the decimal separator (not needed without decimals).
Last is the thousands separator.

(You probably set the number of decimals to 3)


Please see THIS for a complete explanation of number_format().
For example you would need number_format($number, 0) if the default settings are present or number_format($number, 0, '.', ',') for comma to be used as thousand seperator.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜