PHP, for <= not expected results with decimals

When I run this PHP (5.4.31, running on 32-bit windows xp) code I get the result I’d expect:

for($i = 0; $i <= 10; $i = $i + 0.5)
    echo $i .' ';

But if I move the decimal point over as so:

for($i = 0; $i <= 1; $i = $i + 0.05)
    echo $i .' ';

despite the <= clause, the loop quits at 0.95 instead of at 1.

I’m aware that there is an imprecise nature to floating point numbers, but this seems kind of extreme.


Source: stackoverflow-php