What is the inclusive range of float and double in Java?

前端 未结 5 566
你的背包
你的背包 2020-11-28 12:22

What is the inclusive range of float and double in Java?

Why are you not recommended to use float or double for anything where precision is critical?

5条回答
  •  星月不相逢
    2020-11-28 13:02

    Java's Double class has members containing the Min and Max value for the type.

    2^-1074 <= x <= (2-2^-52)·2^1023 // where x is the double.
    

    Check out the Min_VALUE and MAX_VALUE static final members of Double.

    (some)People will suggest against using floating point types for things where accuracy and precision are critical because rounding errors can throw off calculations by measurable (small) amounts.

提交回复
热议问题