$r = 302 / 490;
printLn($r);
printLn(round($r, 2, PHP_ROUND_HALF_UP));
Gives
0.61632653061224484947189239392173476517200469970703125 0.61999999999999999555910790149937383830547332763671875
Why not normal rounding to really 2 digits?
$r = 302 / 490;
printLn($r);
printLn(round($r, 2, PHP_ROUND_HALF_UP));
Gives
0.61632653061224484947189239392173476517200469970703125 0.61999999999999999555910790149937383830547332763671875
Why not normal rounding to really 2 digits?
To within the measurable precision of floating-point numbers, the rounded number shown is 0.62
. To understand why you aren't getting exactly 0.62
, you need to understand how floating-point numbers work. Basically you can take any integer of magnitude up to 253-1 and multiply it by any power of 2 between -1074 and 971 (inclusive). 0.62
cannot be exactly represented in this manner.
Put another way, your precision
INI setting is too high. See this codepad. Try setting it to a more representible number, like the default 15.