Is it safe when compare 2 float/double directly in Java?

后端 未结 9 1007
刺人心
刺人心 2020-12-17 02:30

Is it safe if I use comparision like this (a is int, b and c is float/double):

a == b
b == c

It may hear ridiculous, but in my old programi

9条回答
  •  粉色の甜心
    2020-12-17 03:15

    Float wrapper class's compare method can be used to compare two float values.

    Float.compare(float1,float2)==0
    

    It will compare integer bits corresponding to each float object.

提交回复
热议问题