Topic: 5/10 = 0? Data type questions

If I open up irb (or the rails script/console) and type

5/10

I get 0.  It seems like I should get .5

If I use to_f on the Fixnum objects (to make them floats) I get .5 as expected

irb(main):002:0> 5.to_f / 10.to_f
=> 0.5

Maybe I'm just used to PHP assuming what certain things should be (integers, strings, floats etc.) but do I have to convert every Fixnum to a float if I want to preform some division?

Re: 5/10 = 0? Data type questions

As long as one of the numbers are a float you'll get the results you're looking for:

  5.0 / 10      #=> 0.5

Vincent Woo Ruby on Rails Blog

Re: 5/10 = 0? Data type questions

AHHHH very interesting, well that is helpful.