Monday, March 10, 2008

Integer division

I was trying to divide 3 by 5 (3/5) and I never got the correct result. I got back 0 all the time which is obviously not correct. But when I did 6/2 I got back 3. So when I researched a little I found out that it defaults to integer division in Ruby. That means it doesn't divide the integer if the resultant is going to be a float. So I had to do this: 3.to_f/5.to_f.

An interesting discussion about this point:

No comments: