r/learnruby • u/throwawayIWGWPC • May 25 '15
Integer Division
As a Python newbie, I expected the following to do float division.
x = 9. / 2 # Integer division, Result: 4
y = 9 / 2. # syntax error, unexpected
# end-of-input, expecting '('I'm fine with Ruby not taking a naked decimal to denote floats. However, what is confusing is that I get integer division with the first line and an error with the second line. I'm curious why this is the case.
Thanks!
5
Upvotes
View all comments
Show parent comment
2
u/throwawayIWGWPC May 25 '15
Beautiful explanation. Thanks so much!