I just encountered this and can\'t figure out why exactly Ruby behaves this way.
Could someone explain why in Ruby:
6.84 - 3.6 == 3.2399999999999998
Float/Double is not that precise in most cases (because floats interpolate numbers with base2). The result of floating point operations may vary on different CPU's. The area close to .01 is more precise than the area close to .99
If you need to compare values calculated with float operations use an epsilon value (really small value) in order to erase rounding errors.
Pseudocode:
boolean equals(float x, float y) {
float result = x - y;
if(result*result < epsilon)
return true;
else
false;
}