Is it wrong to compare a double to 0 like this: doubleVariable==0?

后端 未结 6 705
夕颜
夕颜 2021-01-04 04:57

It is ok to do this?

double doubleVariable=0.0;
if (doubleVariable==0) {
   ...
}

Or this code would suffer from potential rounding problem

6条回答
  •  借酒劲吻你
    2021-01-04 06:00

    hmm... I think as long as the number has an exact binary fraction representation (like 0) the comparison is perfectly valid.

提交回复
热议问题