I disagree that you should avoid floating point numbers, they are an essential tool for mathematics. You just need to appreciate that, as in any real life measurement, floating point numbers have a degree of accuracy (or a degree of inaccuracy if you like). It's like the following pitfall:

"I have 31 sheets of card, all seemingly identical. I want to know how thick each one is. I measure them and the total thickness is 17 millimeters. Therefore the thickness of each is 17/31 = 0.548387096774194 mm."

Do you see how this is a ridiculous claim to make? There is no way we can claim to know the thickness of the sheets of cardboard to 20 (or whatever) places, and at this degree of precision there would be massive variation between sheets.

So, don't avoid floating point numbers, just be aware when converting them to integers that you may get unpredictable results. The unpredictability can be minimised by using .round instead of .to_i though:

>> (0.29*100).to_i

=> 28

>> (0.29*100).round

=> 29

###########################################

#If i've helped you then please recommend me at Working With Rails:

#

http://www.workingwithrails.com/person/ … i-williams