From: Michael Morin Date: 2008-11-08T16:03:23+09:00 Subject: Re: what's easiest way to compare a Float & BigDecimal (i.e. like a equals mechanism) Greg Hauptmann wrote: > Hi, > > what's easiest way to compare a Float & BigDecimal (i.e. like a equals > mechanism)? It seems that "==" does NOT work as they are different > types. Is there a way to do a comparison without having to convert > types? > > ?> a > => # >>> x > => 6.5 >>> a == x > => false #<<== DIDN'T WORK > > tks > It works fine for me. If I do something like this: f = 0.1 b = BigDecimal.new('0.1') puts 'yes' if f == b It will return true. I've always stayed clear of the equality operator with floating point numbers. Floating point cannot represent all numbers exactly, so comparing it with something like a BigDecimal (which can represent all numbers exactly) might be problematic.