Is there a function in PHP which automatically adds periods to large numbers?
Asked by
klaas4 (
2194)
May 19th, 2009
e.g. 1000000 turns into 1.000.000?
Observing members:
0
Composing members:
0
5 Answers
number_format does this (in addition to decimalization). You can specify the separators to use, which in your case are periods instead of commas.
It looks like you’ll want to use:
number_format($number, 2, ’,’, ’.’)
Thanks again Richard! I didn’t want the decimals, so I used number_format($number, ’’, ’’, ’.’) instead, which works like a charm! =)
@klaas4 Protip: I would use number_format($number, 0, ’’, ’.’) instead, since the second parameter is expected to be an integer. In the second usage description, you can see:
string number_format ( float $number , int $decimals , string $dec_poi…
Which tells you that it expects an “int” for $decimals.
—
The PHP variable types are:
boolean: truth value (true or false)
integer: round numbers (0, 196, 333, ...)
float: floating-point number or ‘double’ (0.928, 23.0, 1.4, ...)
string: “Hello World”
and then you have compound types like arrays and objects (and then special types).
Hope this helps, good luck with your project!
Answer this question
This question is in the General Section. Responses must be helpful and on-topic.