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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
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.
This topic is locked and can not be replied to.