Float vs Double

后端 未结 7 1832
-上瘾入骨i
-上瘾入骨i 2021-01-17 23:56

Is there ever a case where a comparison (equals()) between two floating point values would return false if you compare them as DOUBLE

7条回答
  •  深忆病人
    2021-01-18 00:21

    You should be okay to make that cast as long as the equality test involves a delta.

    For example: abs((double) floatVal1 - (double) floatVal2) < .000001 should work.

    Edit in response to the question change

    No you would not. The above still stands.

提交回复
热议问题