I'm always wary of adding and subtracting floating point numbers, as they can cause some errors when truncating instead of round.
My question though: will an integer divided by 100 ever cause floating point errors in PHP?
I.e. is it "safe", should I always rely on round($x / 100, 2)
?
Yes. Actually, since 100 isn't a power of two, the result of $x / 100
will always be inexact unless $x
is a multiple of 25. (You get 4 for free since 4 is a power of 2.)