From: doug meyer Date: 2007-08-31T11:50:49+09:00 Subject: Re: 0.06 == 0.06 returns false in Ruby? There is also a class called BigDecimal (or something like that) if you want to have really accurate numbers and no floating-point errors. On 8/30/07, Dan Zwell wrote: > Dan Zwell wrote: > > To compare floats, you must ask whether they are within a certain > > threshold of each other. > > Epsilon = 0.00000000001 > > return (num1-num2).abs < Epsilon # num1 == num2 > > > > Dan > > > > > > Oops, I didn't realize that Ruby comes with an Epsilon. This should be a > fine test for equality: > > return (num1-num2).abs < Float::EPSILON > > Now, whether Float#==(other) should make this check might be worth > thinking about, but I really have no opinion on the matter--I'm used to > not comparing floats like this. > > Dan > >