红宝石算术 [英] Arithmetic in ruby
本文介绍了红宝石算术的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
7.30 - 7.20
在ruby中返回 0.0999999999999996
,而不是 0.10 code>?
但是,如果我写 7.30 - 7.16
,例如,一切都会好的,我会得到 0.14
。
什么问题,我该如何解决?
解决方案
Why this code 7.30 - 7.20
in ruby returns 0.0999999999999996
, not 0.10
?
But if i'll write 7.30 - 7.16
, for example, everything will be ok, i'll get 0.14
.
What the problem, and how can i solve it?
解决方案 What Every Computer Scientist Should Know About Floating-Point Arithmetic
这篇关于红宝石算术的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文