0

I have the following code

$suma += round(1*43067.8000,2);

$suma += round(-1*18875.1800,2);

$suma += round(-1*15293.9700,2);

$suma += round(-1*8898.6500,2);

print $suma;

The output is 3.6379788070917E-12

Why the answer is not 0 if the number is rounded before the addition?

pilu
  • 33
  • 7

1 Answers1

2

Round still returns a float. Because it is a float there might always be very small errors. In this case, this causes your answer to differ from 0.

Patrick Kostjens
  • 5,065
  • 6
  • 29
  • 46