I am trying to round the double 0.0045. When I call…
echo round($theFloat, 3);
I get 0.004, instead of 0.005 which is the expected response.
Here is the code:
$increase = 1.1;
$previousPrice = round(0.11 / $increase, 2);
$nextPrice = round(0.11 * $increase, 2);
$afterCut = round(0.11 * 0.95, 6);
$willSend = $afterCut - $previousPrice;
echo round($willSend, 3);
Although what you have looks like 0.0045, the value is actually approximately 0.00449999999999999966, since IEEE 754 floating point values cannot specify exactly that number. And that value, when rounded to 3 places, is 0.004.