添加浮点数的奇怪结果 [英] Strange result with floating point addition
本文介绍了添加浮点数的奇怪结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么我打印/显示结果
Why is it when I print/display the result of
eval("11.05") + eval("-11")
它出现为0.05000000000000071而不是预期的0.05。有什么我想念的吗?
it comes out as 0.05000000000000071 instead of the expected 0.05. Is there something I am missing?
推荐答案
这与 eval $ c $无关C>。事实上,如果您输入控制台会发生这种情况
11.05 - 11
:
This has nothing to do with eval
. In fact, this is what happens if you type in a console 11.05 - 11
:
这是编程语言如何存储浮点数的结果;它们包含一个小错误。如果您想了解更多相关信息,请查看此信息。
This is a consequence of how programming languages store floating-point numbers; they include a small error. If you want to read more about this, check this out.
这篇关于添加浮点数的奇怪结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文