• 注册
当前位置:1313e > java >正文

java控制float精度_java – 关于float类型的精度

How does it manage to keep max_value of integer,which is 2^31 – 1?

它实际上没有. f的值是2147483648.

Otherwise,one of the following two cases must be true:

The value must be too small (a negative value of large magnitude or negative infinity),and the result of the first step is the smallest representable value of type int or long.

The value must be too large (a positive value of large magnitude or positive infinity),and the result of the first step is the largest representable value of type int or long.

通过使数字更大,您可以轻松地看到这一点:

float f = Integer.MAX_VALUE;

f = f * 1000;

System.out.println(Integer.MAX_VALUE); // 2147483647

System.out.println((int)f); // 2147483647

或者通过铸造来代替,显然不需要在同一点夹紧:

float f = Integer.MAX_VALUE;

System.out.println(Integer.MAX_VALUE); // 2147483647

System.out.println((long)f); // 2147483648

本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 162202241@qq.com 举报,一经查实,本站将立刻删除。

最新评论

欢迎您发表评论:

请登录之后再进行评论

登录