float number is not the expected number after subtraction

前端 未结 4 592
傲寒
傲寒 2020-12-19 15:53

I have the following statement:

float diff = tempVal - m_constraint.getMinVal();

tempVal is declared as a float and the

4条回答
  •  無奈伤痛
    2020-12-19 16:38

    Java encodes real numbers using binary floating point representations defined in IEEE 754. Like all finite representations it cannot accurately represent all real numbers because there is far more real numbers than potential representations. Numbers which cannot be represented exactly (like 0.1 in your case) are rounded to the nearest representable number.

提交回复
热议问题