This looks like floating point vagaries. I did a bit of digging:
>>> (5.02 / 0.01)
=> 502.0
>>> intval(5.02 / 0.01)
=> 501
>>> intval(502.0)
=> 502
>>> round(5.02 / 0.01)
=> 502.0
If you add a very tiny amount, you can make it tip over:
intval(5.02 / 0.01 + 0.0000000000001)
=> 502
This isn't particularly satisfying, I'll grant, but probably the cleanest way to do it is to round rather than cast straight to int. Your workaround is effective (at least in this case) because it forces PHP to treat the result as a string instead of a float, which (int)
then casts quite easily:
>>> 5.02 / 0.01 . ''
=> "502"
>>> (int)(5.02 / 0.01 . '')
=> 502
See here for more info. Note this is why generally for values where accuracy matters, such as currency, it is recommended to use integers.
For example, if you are dealing in pounds/pence (or dollars/cents), you would store and evaluate all calculations in pence (or cents) and then divide by 100 at the last minute when you display the result.