From: Robert Klemme Date: 2007-07-17T22:32:27+09:00 Subject: Re: Force calculation result to BigDecimal 2007/7/17, Todd Benson : > On 7/17/07, Robert Klemme wrote: > > > Hm.... I don't think this is a fix because once you have a float you > > lost all the precision. > > Can you elaborate on this? I was under the impression that converting > to BigDecimal before arithmetic operations would get around this. Actually you are right. I somehow thought you intended #big to be called on the result, i.e. after the calculation. Stupid me. Sorry for the confusion. > Using > class Float > def big; BigDecimal(self.to_s); end > end > irb > Math::PI.big * 2.0 > => 6.283185307178 > irb > Math::PI.big * 2.0.big > => # > > > A better fix is probably to change #coerce to > > work properly. Another solution is to make sure all values are > > converted to BD before starting the calculation. > > This would be the best solution (maybe through #induced_from?), but I > don't know how to do it. It would take me too much time ATM to do it and it should also be checked whether changing #coerce causes issues somewhere else... Kind regards robert