echo (int) ( (0.1+0.7) * 10 );
Why does the above output 7? I understand how PHP rounds towards 0, but isn\'t (0.1+0.7) * 10 evaluated as
(0.1+0.7) * 10
The other answers explained WHY this happens. This should get you what you want:
echo (int) round( (0.1+0.7) * 10 );
Just round the float before casting it to an int.