From: Gary Wright Date: 2012-01-21T23:33:47+09:00 Subject: Re: Microrant on Ruy's Math Skills 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") => # >> puts BigDecimal.new("1.1") - BigDecimal.new("1.0") 0.1