Why is PHP typecasting behaving like this? (int) mis-rounding numbers?

Viewed 408

Could someone please explain what is going on here?

echo (18.99 * 100); // output: 1899

echo (int)(18.99 * 100); // output: 1898

The only thing I can possibly think of is that the 1899 is actually 1898.999999999999 or something and PHP is converting it as part of echo somehow? If this is the case, why? If not, what is the reason for this strange behaviour?

1 Answers
Related