title: PHP floating point error with basic arithmetic operation
body: <p>I am new to PHP and trying to perform a simple arithmetic addition and comparison. I have an array with some decimal values and after adding all the values, I am trying to compare it to 1. My array is:</p>
  
  <pre><code>$myArray=[0.2,0.7,0.1] 
  </code></pre>
  
  <p>and my code is:</p>
  
  <pre><code>$sum=0;
  foreach($myArray as $val){
      $sum+=$val;             
  }
  </code></pre>
  
  <p>Here, the sum comes out to be 1. But when I compare it using the following code: </p>
  
  <pre><code>if($sum!=1)
  {
      echo "Good";
  }
  else
  {
      echo "Bad";
  }
  </code></pre>
  
  <p>it echoes <code>"Good"</code>.</p>
  
  <p>However, when my array contains values 0.8 and 0.2, it echoes <code>"Bad"</code>. Can anyone help me on this?</p>