From: Eric Hodel Date: 2008-12-23T13:11:49+09:00 Subject: [ruby-core:20814] Re: [Bug #922] Float == is false when should be true On Dec 22, 2008, at 19:55 PM, Amanda Nicholas wrote: > Bug #922: Float == is false when should be true > http://redmine.ruby-lang.org/issues/show/922 > > Author: Amanda Nicholas > Status: Open, Priority: Normal > Target version: Ruby 1.8.7 > > In irb on Ruby 1.8.6 (ruby 1.8.6 (2007-09-24 patchlevel 111) [i486- > linux]) and 1.8.7 (ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux]) > >>> 896.5 * 0.83 > => 744.095 >>> 896.5 * 0.83 == 744.095 > => false They're not the same, Ruby truncates the true value for display purposes: irb(main):001:0> a = 896.5* 0.83 => 744.095 irb(main):002:0> b = 744.095 => 744.095 irb(main):004:0> "%0.26f %0.26f" % [a, b] => "744.09499999999991359800333157 744.09500000000002728484105319" See also: http://en.wikipedia.org/wiki/Floating_point