Treat
Treat

Reputation: 192

php formatting numbers?

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

1=1
10=10
100=100
1000=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.

Upvotes: 0

Views: 202

Answers (2)

Christoph Fink
Christoph Fink

Reputation: 23113

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.

Upvotes: 0

Kokos
Kokos

Reputation: 9121

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)

Upvotes: 2

Related Questions