可能重复:
Floating point inaccuracy examples
Floating point comparison
Computers are meant to be good at arithmetic, aren't they? Why does this print "False"?
double d1 = 1.000001;
double d2 = 0.000001;
Console.WriteLine((d1-d2)==1.0);
或者c sharp或java
的结果会有所不同答案 0 :(得分:1)
我认为结果可能会有所不同,具体取决于您使用的处理器和语言
这是因为浮点数(通常)存储有多个位,这些位试图表示该小数,但可能存在一些(非常小的)差异。
所以当你做(d1-d2)
时,你可能得到一个非常接近1.0的数字,但不完全是1.0 !!