This question already has an answer here:
Hi i got some problem with rounding. For ex.:
$x = 100;
$y = 4.2030;
$result = round($x / $y, 2);
$result will be 23.79
but now
$result2 = round(23.79 * 4.2030, 2);
$result2 will be 99.99 , so it's incorrect. should be 100 ($result2 equal $X)
how to slove it ?
</div>
Your round precision is two decimal places. If you are trying to get whole numbers you need to omit the precision argument:
$result2 = round(23.79 * 4.2030);
NOTE: the lower the precision argument, the more inaccurate your result will be from the actual results.
You can also use ceil()
and floor()
if you are looking to round in a specific direction (ceil()
will round up, floor()
will round down).