[問題] 浮點數錯誤

看板Python作者 (初夏預言)時間4年前 (2020/11/02 15:53), 編輯推噓2(201)
留言3則, 3人參與, 4年前最新討論串1/3 (看更多)
我剛才在 Spyder 的 iPython console 做簡單的加法,會出現浮點數錯誤。 請問這個計算誤差要如何避開或消除?謝謝。 In [5]: 0.86 + 3.2 Out[5]: 4.0600000000000005 In [6]: 3.86 + 0.2 Out[6]: 4.06 https://imgur.com/XpcRrka
-- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.229.98.97 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1604303603.A.61F.html

11/02 16:13, 4年前 , 1F
改用decimal?
11/02 16:13, 1F

11/02 19:38, 4年前 , 2F
這很正常,高精度浮點計算要Decimal
11/02 19:38, 2F

11/09 13:20, 4年前 , 3F
ieee754可以了解一下
11/09 13:20, 3F
文章代碼(AID): #1VdxhpOV (Python)
文章代碼(AID): #1VdxhpOV (Python)