On Jan 21, 2012, at 9:06 AM, Intransition wrote:

> So simple...
> 
>   1.1 - 1.to_f == 0.1
>   >> false
> 
> (*rumble*) (*rumble*) Pathetic!


Decimal literals (e.g. 1.1) can't always be represented exactly as binary floats:

>> "%.40f" % 1.1
=> "1.1000000000000000888178419700125232338905"
>> "%.40f" % 1.0
=> "1.0000000000000000000000000000000000000000"
>> 

Use BigDecimal if you need exact precision:

>> require 'bigdecimal'
=> true
>> BigDecimal.new("1.1") - BigDecimal.new("1.0")
=> #<BigDecimal:7fc50ea75ff0,'0.1E0',9(36)>
>> puts BigDecimal.new("1.1") - BigDecimal.new("1.0")
0.1