From: "Stephan Kämper" Date: 2004-05-13T05:38:53+09:00 Subject: Re: Major Addition Bug? Hal Fulton wrote: > > Seriously, I think it's a matter of trying to store an infinite > number of digits in a finite number of bits. > > For a daily life example: How many digits does it take to store > "1/3" exactly? 0.333333... SCNR, but: irb(main):001:0> 1/3 => 0 *That* result fits into a single bit. ;-) But in general there's not much to add to this thread, but to summarize it: - For financial calculations use specialised classes (which should handle different currencies, BTW) - If you *need* a higher number of digits use BigDecim (which is documented in the 'Ruby Standard Library Documentation' available at http://www.ruby-doc.org/downloads/stdlib/ ) - Never, repeat *never* compare floats with == or other operators like that. Define some kind of accuracy, say epsilon and use a usual metric like this: ( a_value - something_else ).abs < epsilon - Don't use == to compare floats and last but not least - Comparing floats with == is a Bad Thing. Well, that's it - more or less. Happy rubying, Stephan