以下是代码:
double d1 = 2.4066419461049408E7;
double d2 = 500.0;
int retval = Double.compare(d1, d2);
if(retval > 0) {
System.out.println("d1 is greater than d2");
} else if(retval < 0) {
System.out.println("d1 is less than d2");
} else {
System.out.println("d1 is equal to d2");
}
输出:
d1 is greater than d2
为什么?如何得到正确答案?
1条答案
按热度按时间jq6vz3qz1#
这是正确的答案:
2.4066419461049408E7
远大于500.0
注意E7
在第一个数字的末尾:这意味着x10^7
(指数)。你这样比较
24066419.461049408
到500.0
.