Junit中對兩double型別值的比較

2021-09-20 06:10:14 字數 298 閱讀 8176

使用junit 4 測試正確性時出現以下錯誤

the method assertequals(double,double) from the type assert is deprecated

經查閱相關資料發現junit中沒有assertequals(double,double) 的方法,因為double值比較相等時存在誤差

需要用assertequals(double,double,double) 方法進行比較

其中第三個引數為誤差

新增誤差後測試通過

參考資料:

Junit中對double型別進行assert對比

在junit測試中使用到了將double型別的資料進行比較,但是出現以下錯誤 報錯資訊 the method assertequals double,double from the type assert is deprecated junit中沒有assertequals double,doubl...

Junit中double型別的比較

在寫junit單元測試的時候發現直接用assertequals double,double 比較時會發生錯誤。報錯資訊 the method assertequals double,double from the type assert is deprecated junit中沒有assertequ...

Java中對double型別保留兩位小數的方法

整理了網上一些方法,方便以後查閱。1.使用bigdecimal類 bigdecimal b1 new bigdecimal width bigdecimal b2 new bigdecimal height bigdecimal b3 b1.multiply b2 return b3.setscal...