Reputation: 11
I do not understand php:
echo -0.01-0.02-0.16+0.01+0.01+0.17;
result 2.7755575615629E-17
correctly = 0 !
Upvotes: 1
Views: 115
Reputation: 1148
The answer you got is accurate answer according to BODMAS rule if you want round up answer than just use round()
function of PHP. You will get you answer.
echo round(-0.01-0.02-0.16+0.01+0.01+0.17, 8);
Upvotes: 0
Reputation: 3799
E-17 really means x 10 ^ (-17).
According to the computer, which suffers from precision errors at the far end of decimal floating point numbers, it is calculating your answer to be 0.00000000000000002775557...
If you don't need that sort of precision, you can force rounding to a certain accuracy:
echo round(-0.01-0.02-0.16+0.01+0.01+0.17, 8);
Upvotes: 3