number_format???

A

Anonymous

Guest
Hope someone could help to explain my doubt.
when i write:
number_format(2.175, 2, '.', ',') ----i get 2.17

but when i put:
number_format(2.375, 2, '.', ',') ----i get 2.38, why is not 2.37
 
could be a glitch possibly...
have you tried it on several occasions? do you get the same result all the time?
 
i have tried out several this type of number,
the result is not consistant, but it always get some different results in one list. (x.0x5 to x.9x5)
 
Well, it seems that, by default it rounds the number!
So if you use number_format(2.374, 2, '.', ',') the output will be: 2.37 and not 2.38!

It won´t happen if you use number_format(whatever, 3, 'whatever', 'whatever').

Anyway, this all makes sense, but there´s one thing i don´t understand! following this idea, we can see that it doesn´t happen with the first one. It should output 2.18 instead of 2.17 and it only happens if we have number_format(2.176, 2, '.', ',') ...

Yeh... it´s stranger :???:

Gesf
 
http://www.php.net/number_format
in Contributors Note you may see some examples....
 
Yes WiZARD, i already saw that and it makes sense when it rounds the number. I just don´t understand why it doesn´t happen with the iamoklah first example.

Well, the same happens in a contributor´s function where he uses the round() function... Don´t know why!

Gesf
 
gesf said:
Yes WiZARD, i already saw that and it makes sense when it rounds the number. I just don´t understand why it doesn´t happen with the iamoklah first example.

Well, the same happens in a contributor´s function where he uses the round() function... Don´t know why!

Gesf
I think what better ask about it at the developers of PHP....
It's mathematic and need to see source code.....
Sorry, but i'm not have a time for it :sad:
 
That´s ok!
I don´t want you to make mathematic calculations :p
I don´t even like math, so... let´s leave it to the php developers ;)

Gesf
 
Back
Top