Forum: Ruby Why won't this convert into a float?

330706f815a29c699bbad1d046352fd8?d=identicon&s=25 Eric Lecarde (holmcross)
on 2014-07-02 01:39
If ary = [2,3,4] and @result /= (@ary.pop.to_f)./(@ary.pop.to_f), why
does @result not convert to float? The answer should be .75, but it
keeps ending up as 0.0.

Thanks.
54404bcac0f45bf1c8e8b827cd9bb709?d=identicon&s=25 7stud -- (7stud)
on 2014-07-02 03:18
ary = [10, 2, 4]

result = 8
result /= (ary.pop.to_f)./(ary.pop.to_f)

p result
p result.class

--output:--
4.0
Float

$ ruby --version
ruby 1.9.3p547 (2014-05-14 revision 45962) [x86_64-darwin10.8.0]

$ rvm use 2.0
Using /Users/7stud/.rvm/gems/ruby-2.0.0-p481
~/ruby_programs$ r 1.rb
4.0
Float

$ rvm use 2.1
Using /Users/7stud/.rvm/gems/ruby-2.1.2
~/ruby_programs$ r 1.rb
4.0
Float


> The answer should be .75

I think it should be 42.333555...or maybe -3.2.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.