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.
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.
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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs