I have small problem and it might be silly somewhere, but still i have it 🙂
So the problem is:
By doing this
round(615.36*0.10, 2, PHP_ROUND_HALF_DOWN);
I expect outcome to be 61.53, but it’s 61.54.
phpVersion = 5.3.2
Could anyone help me to solve this?
Thanks.
PHP_ROUND_HALF_DOWNwill round the half — i.e. the0.005part.if you have
61.535, usingPHP_ROUND_HALF_DOWNwill get you61.53— instead of the61.54you should have obtained with usual rounding.Basicall, the
.005half has been rounded down.But
61.536is not a half :.006is more than.005; so rounding that value gives61.54.In your case, you could multiply the value by 100, use the floor() function, and divide the result by 100 — I suppose it would give you what you expect :
Gives me :