From: Hal Fulton Date: 2004-10-28T05:32:18+09:00 Subject: Re: Rounding error, (100.0 * 9.95).to_i == 994 Dan Janowski wrote: > I would agree if it were not for this: > > $ ruby -e 'puts (100.0*9.95).to_s' > 995 > $ ruby -e 'puts (100.0*9.95).to_i.to_s' > 994 > > Ruby seems to be able to manage the FP error rate since FP.to_s show the > exact value. Why shouldn't to_i benefit? > > It seems to me that this type of intolerance would effectively make to_i > not only worthless but dangerous. I sympathize, but I think the point is this: - to_i doesn't round, it truncates; - you have #round if you want to use it; - to_s has to either round or truncate; rounding seems logical - therefore expr.to_s and expr.to_i.to_s may differ It's a matter of opinion, but I think it's working properly. Just another of hundreds of design issues Matz has faced. Hal