This question already has an answer here:
- Is floating point math broken? 30 answers
I try intval(6.02 * 100)
,the result is 602。but why the result of intval(5.02 * 100)
is 501?
</div>
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?