看板 Python 關於我們 聯絡資訊
我執行 >>> 10 * 0.000001 == 1 * 0.00001 False 應該是python 精度的問題 請問有辦法讓這兩個相等嗎? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 118.150.128.77 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1532593374.A.B0A.html
IAMPF: 10 * 0.000001 - 1 * 0.00001 < sys.float_info.epsilon 07/26 16:34
TuCH: round(10*0.000001,10)==round(1*0.00001,10) 07/26 16:36
TuCH: Decimal('10')*Decimal('0.000001)==Decimal('1')*Decimal(' 07/26 16:37
TitanEric: 推一樓方法 不要直接用等於 這是IEEE 754 07/26 17:53
f496328mm: 一樓的方法好'數學' 07/26 17:54
sherees: 用一樓的方法記得加絕對值喔 07/27 11:26
sherees: 因為sys.float_info.epsilon>0 所以負數會是True 07/27 11:27
sherees: 舉個例子1-2>epsilon>>True 但1!=2 這個結果明顯是誤判 07/27 11:32
sherees: < 07/27 11:33
sherees: 更正 07/27 11:34