PHP expression output -


this question has answer here:

i found somewhere in book

echo (int) ((0.1 + 0.7) * 10);  

output : 7

echo ((0.1 + 0.7) * 10); 

output : 8

why both out different ? think answer should 8

when write

echo ((0.1 + 0.7) * 10); 

the result of simple arithmetic expression stored internally 7.999999 instead of 8.

now when value converted int,

 echo (int) ((0.1 + 0.7) * 10); // 7.999999 when typecasted int becomes 7 

php truncates away fractional part, resulting in rather significant error (12.5%, exact).


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -