From: Stefan Rusterholz Date: 2007-07-19T23:11:54+09:00 Subject: Re: Float.to_int not working ?? unknown wrote: > Hi all, > > I must admit that I am new to Ruby, so maybe this is not a real bug?! > > Trying the following > > print "#{((1.0 + 0.025)/0.0002 + 1.0)} \n" > print "#{((1.0 + 0.025)/0.0002 + 1.0).to_i} \n" > > I get (with ruby 1.8.4 & 1.8.5, Linux) as output > > 5126.0 > 5125 > > Any suggestions? Yes. Learn about floats. Floats are approximations, that has some consequences. As for your code above: printf "%.40f\n",((1.0 + 0.025)/0.0002 + 1.0) # prints: 5125.9999999999990905052982270717620849609375 Now you see why .to_i gives you 5125. Regards Stefan -- Posted via http://www.ruby-forum.com/.