Java:计算返回错误的答案? [英] Java: Calculations returning wrong answer?
本文介绍了Java:计算返回错误的答案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
用java中的双打保留精度
将小数点移动到双倍中
例如,这很简单:
public class WrongAnswer {
public static void main(String[] args) {
System.out.println(100*1.1);
}
}
打印110.00000000000001而不是110.使用其他数字代替100 * 1.1也给出了很多数字,最后一些随机数字是不正确的..
prints 110.00000000000001 instead of 110. Using other numbers instead of 100*1.1 also give a lot of digits with some random digit at the end that isn't right..
任何想法?
推荐答案
浮点表示法的准确度有限。以下是指南: http://floating-point-gui.de/
Floating point notations have limited degrees of accuracy. Here's a guide: http://floating-point-gui.de/
这篇关于Java:计算返回错误的答案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文