Float vs Double

后端 未结 7 1828
-上瘾入骨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:18

    For the comparison between float f and double d, you can calculate the difference of f and d. If abs(f-d) is less than some threshold, you can think of the equality holds. These threshold could be either absolute or relative as your application requirement. There are some good solutions Here. And I hope it helpful.

提交回复
热议问题