我尝试`intval(6.02 * 100)`,结果是602,但为什么`intval(5.02 * 100)`的结果是501? [重复]

This question already has an answer here:

I try intval(6.02 * 100),the result is 602。but why the result of intval(5.02 * 100) is 501?

</div>

This is a floating point math issue. The following might help explain it:

ini_set('precision', 17);
echo (float)5.02;

5.0199999999999996

echo 5.02 * 100;

501.99999999999994

echo intval(501.99999999999994);

501

More discussion on this topic: php intval() and floor() return value that is too low?