phparray-sum

array_sum PHP wrong result


the result of this should be zero!

echo array_sum([-61.50,50.00,10.50,1.00,0.00,50.00,-16.73,-20.00,-55.75,42.48]);

Why is giving -7.105427357601E-15?


Solution

  • Just try round(), you will get the same result.

    echo round(array_sum([-61.50,50.00,10.50,1.00,0.00,50.00,-16.73,-20.00,-55.75,42.48]));