Can someone explain what is happening here? I have floating point number that is to be rounded to two decimal points (price).
echo $total . " is rounded to " . round((float)$total,2);
var_export((float)$total);
echo " is rounded to ";
var_export(round((float)$total,2));
echo "\r\n";
Output is: 79.95 is rounded to 79.95 79.9500000000000028421709430404007434844970703125 is rounded to 79.9500000000000028421709430404007434844970703125
So, "echo" rounds to itself. When I use var_export() to output data, seem that round() is not working.
Just for test, I made:
$total = 79.9501234576908988888;
Then I get: 79.950123457691 is rounded to 79.95 79.9501234576908927920158021152019500732421875 is rounded to 79.9500000000000028421709430404007434844970703125
So, "echo" seem to automatically round floats to 11 decimal points. Why round() is not working with var_export is a mystery.
Does anyone have an explanation?
Thanks,
Rudolf