General Question

klaas4's avatar

Is there a function in PHP which automatically adds periods to large numbers?

Asked by klaas4 (2189points) May 19th, 2009

e.g. 1000000 turns into 1.000.000?

Observing members: 0 Composing members: 0

5 Answers

richardhenry's avatar

number_format does this (in addition to decimalization). You can specify the separators to use, which in your case are periods instead of commas.

richardhenry's avatar

It looks like you’ll want to use:

number_format($number, 2, ’,’, ’.’)

klaas4's avatar

Thanks again Richard! I didn’t want the decimals, so I used number_format($number, ’’, ’’, ’.’) instead, which works like a charm! =)

richardhenry's avatar

@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!

klaas4's avatar

Ah, I see, thanks!

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther