From: Farrel Lifson Date: 2008-10-08T07:45:00+09:00 Subject: Re: newbie question Rounding errors in floating point arithmetic. Farrel On 08/10/2008, Will wrote: > Greetings all, I think this is generally more a programming question than a > ruby explicit one, however, I am wondering why this code yields 23, > 0.999999999999979 instead of 23, 1. > > Any help would be great! > > i = 0 > while i <= 50 > a = 37*i / 50 > c = a + 0.0 > b = (37*i/50.0 - c ) *50 > if b < 1.5 && b > 0.5 > puts i > puts b > end > i = i+1 > end > > > thanks much > Will > -- Aimred - Ruby Development and Consulting http://www.aimred.com