謝晒的PHP網頁設計
聯絡E-mail:
sean0704@gmail.com
站內搜尋
Tuesday, September 13, 2016
[PHP] 兩個數值比對 與預期結果不一致的解決方法 (PHP小數點(浮點數)的精度問題)
$a = 0.6;
$b = 0.8 - 0.2;
var_dump($a == $b); //false
解法很簡單...
$a = 0.6;
$a = round($a, 1);
$b = 0.8 - 0.2;
$b = round($b, 1);
var_dump($a == $b); //true
參考PHP官網
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment