title: PHP - Comparing double to a string is weird?
body: <p>I'm seeing some weird behavior in php when comparing a double to a string and was hoping someone could explain to me what is going on.</p>
  
  <p>If I declare $num = 0.333;
  and then test 
  $num == '0.333', 
  this comes out as true. If I then add 1 to $num and then subtract 1, then $num == '0.333' comes out as false. If I then cast $num as a string, the comparison goes back to being true. Why is it doing this?</p>
  
  <p>Here's a sample:</p>
  
  <pre><code>&lt;?php
    $num = 0.333;
  
    //returns 0.333 double Yes
    echo $num, ' ', gettype($num), ' ', $num == '0.333' ? 'Yes' : 'No', '&lt;br /&gt;';
  
    $num += 1;
    $num = $num - 1;
  
    //returns 0.333 double No
    echo $num, ' ', gettype($num), ' ', $num == '0.333' ? 'Yes' : 'No', '&lt;br /&gt;';
  
    $str = (string)$num;
  
    //returns 0.333 string Yes
    echo $str, ' ', gettype($str), ' ', $str == '0.333' ? 'Yes' : 'No', '&lt;br /&gt;';
  ?&gt;
  </code></pre>
  
  <p>Thanks.</p>