This question already has an answer here:
Something is wrong with eval
function
$string = '$val = 1526.65 - 1519.99;';
eval($string);
echo $val; => give 6.6600000000001, expected 6.66
The test is here : http://sandbox.onlinephpfunctions.com/code/fa5b2e7e6602e60cdeb054b705a69e4a226bd52c
Anyone have an explanation ?
</div>
This has nothing to do with eval
, since the same result is produced by running that line normally. The reason for the strange result is floating point error.