Can someone please explain this to me?
x = Rational(3/4) * 8
=> (0/1) # I Expected it to return 6
x.to_i
=> 0
Thanks.
Can someone please explain this to me?
x = Rational(3/4) * 8
=> (0/1) # I Expected it to return 6
x.to_i
=> 0
Thanks.
You are creating a
Rational
number with3/4
as the only argument.3/4
is0
, so, your code is equivalent towhich obviously is
0
.Compare this to
where you explicitly pass both the numerator and denominator.