意外的PHP数学小数运算

    $nt=(float) number_format("26031.87",2,".",""); // 26031.87
    $nt2=(float) 546669.02-520637.15; // 26031.87

    if($nt>$nt2)
     echo "$nt / $nt2 ⇽ What's wrong with this!? :@";

the point is why this happen?, if visually looks the same, a chunky solution is doing number_format() to $nt2, but... WHY??

updating :: $nt-$nt2 outputs 3.6379788070917E-12

http://php.net/manual/en/language.types.float.php see that big red warning banner. :)

For comparing floats you can use:

if (abs($nt1-$nt2) < 0.00001) {
    echo "Equal!";
}

(change 0.00001 to comparison precision you need).

Per Zend:

PHP doesn't seem to do the logical thing when comparing two floats, and this is due to the internal representation of the numbers. The solution is simply never compare floats for equality!

Convert them to INT before comparing them or use bc_math.