<?php
$last_percent = 0;
$as = array("110.800002098083", "30", "36.1499996185303", "11", "13", "13.9899997711182", "74.5200042724609", "13.9899997711182");
$t = 304.46000552177;
foreach($as as $a) {
$last_percent += round($a*100/$t, 2);
}
var_dump($last_percent);
$last_percent = 100 - $last_percent;
var_dump($last_percent);
?>
爲什麼結果是0.33000000000001?爲什麼它只發生在100和99?如果我使用$ last_percent = 90 - $ last_percent; 結果是-9.67PHP瘋狂bug
浮動。點。數學。 – rdlowrey
[每個計算機科學家應該知道的關於浮點算術](http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html) – sachleen
http://php.net/manual/ en/language.types.float.php < - 有一個帶有警告的大紅色框。閱讀。 – hakre