From: Lloyd Zusman Date: 2004-05-13T03:50:42+09:00 Subject: Re: Major Addition Bug? ptkwt@aracnet.com (Phil Tomson) writes: > In article <200405121653.i4CGrEm04797@moulon.inra.fr>, > ts wrote: >>>>>>> "S" == Sean O'Dell writes: >> >>S> raise "false" if ((625.91 + 900.00 + 22.00) != 1547.91) >> >> Well, this is well known >> > > I'm not sure how well known this is. Is it well known as being a problem > or well known as in "you should never do this sort of thing". > > Seems to present a major problem if you want to deal with financial > figures, for example. Are there any workarounds? I have been programming for 35 years, and during this time, I keep seeing members of the financial community writing programs that do money math with floating point numbers. Several times in my career we had to rewrite code that mis-used floating point in this way, when people finally realized that they can't get exact results. One way around this in Ruby is to use the BigDecimal class. It allows arbitrary precision math to be performed. There are other solutions, as well. For example, the Rational class can also be used for financial calculations. > Phil -- Lloyd Zusman ljz@asfast.com God bless you.