1
我真的很想知道,爲什麼下面的代碼總是返回7.我真的很困惑。爲什麼這些表達式總是返回7?
$a = (double) ((0.1 + 0.6) * 10); //Output: 7
$b = (int) ((0.1 + 0.6) * 10); //Output: 7
$c = (int) ((0.1 + 0.7) * 10); //Output: 7
輸出測試:
echo ($a == $b && $a == $c); //Output: true
看到http://stackoverflow.com/questions/3726721/php-floating-number-precision – jeroen