Raphael Clancy wrote:

> Just to tack on my 1.9997438 cents ;)
> 
> We had a big go-round about this a while back. This behavior is not 
> specific to Ruby. The reason Ruby behaves like this is that it adheres 
> to the IEEE standard for floating point numbers, which is common to most 
> programming languages. A standard so old that it was first pressed into 
> clay tablets back when computers were powered by oxen and water wheels. 
> Ruby keeps this standard because it's fast and it reflects the way that 
> computers really work with numbers. There are plenty of alternatives for 
> dealing with floating point numbers which are usually offered as high 
> precision scientific numerical packages. But these are almost always 
> slower than the IEEE standard. And, while they are less lousy (I imagine 
> most could keep two decimal places straight) they are still prone to 
> precision error, just because computers are, at their very core, integer 
> only.

Just for "fun", I tried the following on g++ 4.01 (PPC version)

#include <iostream>

using namespace std;

int main(int argc, char* argv[]) {
  float x = 10.12;
  int y = (int) (x * 100.0);
  cout << x << " , " << y << endl;
  return(0);
}

which generates the familiar output...

10.12 , 1011
-- 
Posted via http://www.ruby-forum.com/.