From: oinkoink+unet@... (Bret Jolly) Date: 2004-05-20T15:08:49+09:00 Subject: Re: bad maths A small addendum to my previous answer. If you need exact decimal arithmetic (as you do if the decimals represent dollars and cents) you should use the BigDecimal class. That works in base 10 rather than base 2. (Actually, it works in base 10000, which is mathematically equivalent to base 10.) Imitating your example: require 'bigdecimal' a = BigDecimal("5.5", 20) # the 20 indicates the precision 5.times {puts (a += BigDecimal("0.1")).to_s} # output follows: 0.56E1 0.57E1 0.58E1 0.59E1 0.6E1 No nonsense about 5.99999... here. The BigDecimal class is useful when you want the arithmetic to be decimal rather than binary, and especially when you need extra precision beyond what floating-point can achieve. It is, however, slower than floating point, a bit trickier to use (since you have to set precision or make sure the implicit settings are acceptable) and its method library is less rich than what the Math module provides for Float. Regards, Bret