0

I'm using php5.6 and something is wrong with the code below

    $a = (float)4.2;
    $b = (float)1.4*3; // But 2.1*2 works


    if ($b === $a) {
        die("Equal 1");
    }
    else if ($b == $a) {
        die("Equal 2");
    }
    else {
        die("Not Equal");
    }

The result always is "Not Equal"

Many thanks!!!

qangdev
  • 336
  • 5
  • 15
  • The [PHP Docs](http://www.php.net/manual/en/language.operators.comparison.php) have a big warning about this, with an explanation of how you should [compare float values](http://www.php.net/manual/en/language.types.float.php) – Mark Baker Jun 02 '17 at 11:59
  • @MarkBaker Thanks, I found the solution http://php.net/manual/en/function.bccomp.php – qangdev Jun 02 '17 at 12:04

0 Answers0