java与数学的混淆。第(轮)
以下是一些我感到困惑的代码:
public class MathOpration {
public static void main(String args[])
{
float F1 = -5.5f;
float F2 = 5.5f;
float F3 = -5.49f;
float F4 = 5.49f;
System.out.println("Round F1 is " + Math.round(F1));
System.out.println("Round F2 is " + Math.round(F2));
System.out.println("Round F3 is " + Math.round(F3));
System.out.println("Round F4 is " + Math.round(F4));
}
}
上述结果是:
Round F1 is -5
Round F2 is 6
Round F3 is -5
Round F4 is 5
我的困惑是-5是如何成为F1的输出的
任何帮助都将不胜感激
# 1 楼答案
当你围拢过来,你就上去了
# 2 楼答案
如果结果不是你想要的,你可以随心所欲。看看这个关于舍入的小解释
http://mathforum.org/library/drmath/view/71202.html
# 3 楼答案
请阅读^{} 的文档:
这就解释了为什么} 给出“返回不大于参数且等于数学整数的最大(最接近正无穷大)双精度值”。)
-5.5f
轮到-5,而5.5f
轮到6。(^{