【发布时间】:2014-01-27 16:20:07
【问题描述】:
我很困惑。我正在尝试获取int 值:
Integer ord = new Double(33 / (-2 * 1.1)).intValue();
预期:-15
输出:-14
怎么了?
当我尝试时:
Double d = 33 / (-2 * 1.1);
输出:-14.999999999999998
有什么想法吗?提前致谢!
【问题讨论】:
-
已经够近了。欢迎来到浮点运算。如果你想使用 Math.round() 而不是 .intValue()
-
如果我每次听到这句话都能得到五分钱,我可能会得到 45 美分。
-
整数序 = Math.round(new Float(33 / (-2 * 1.1)));
-
这个问题经常被问到。请花些时间,下次再搜索。
-
@pcnThird 如果我每次听到这句话都能得到五分钱,我可能会得到 44.99987 美分。
标签: java floating-point division