0

For some reason, the == function does not appear to be working for me.

$total = 0;
for($i=0; $i< 5; $i++){
  $total += 10.1;
  print $total . "<br>";
  if($total == 20.2){
    print "SUCCESS<br>";
  }
  if($total == 30.3){
    print "SUCCESS";
  }
  if($total == 40.4){
    print "SUCCESS<br>";
  }
}

This prints out:
10.1
20.2
SUCCESS
30.3
40.4
SUCCESS
50.5

So for some reason it work recognize 30.3 as being equal to 30.3?! Why would this happen? I've tried this with a bunch of other numbers and I cannot figure out why this won't work?

Andrew Sparrow
  • 167
  • 2
  • 2
  • 12

0 Answers0