From: Gary Wright Date: 2010-01-16T06:01:21+09:00 Subject: Re: Float Points error On Jan 15, 2010, at 12:32 AM, Phillip Gawlowski wrote: > On 15.01.2010 05:56, THAKUR PRASHANT SINGH wrote: > >> While retrieving from array I get some number like 22.09000015. >> >> So when I do groupings I miss out my original number as 22.09< >> 22.09000015 >> >> Where as it should come in a group where numbers are 22.09>= 22.09 > > Floats aren't exact, they are approximations: IEEE 754-2008 I see it is time for the Floating Point 101 thread again. Obligatory reference: It is true that floats are approximations of real numbers but the issue that most often trips people up is the conversion between the internal binary representation and the external decimal representation. More specifically, by default Ruby doesn't show you the full precision available in a float: >> 1/3.0 => 0.333333333333333 >> "%0.60f" % (1/3.0) => "0.333333333333333314829616256247390992939472198486328125000000" Lots of discussion in the archives (about once per month I think, maybe more often). Gary Wright