本文介绍了红宝石计算浮动错了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里有什么不对? (ruby version:1.9.2p290(2011-07-09 revision 32553)[x86_64-darwin11.0.0]
x = 523.8
w = 46.9
xm = x + w
assert_equal w,(xm -x)#FAILS with expected,但是
解决方案
From :
阅读链接网站以获取详细信息和解决方法。
Whats wrong here? (ruby version: 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.0.0]
x = 523.8
w = 46.9
xm = x + w
assert_equal w, (xm - x) # FAILS with: <46.9> expected but was <46.89999999999998>
解决方案
From The Floating-Point Guide:
Read the linked-to site for details and ways to get around this.
这篇关于红宝石计算浮动错了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!