Forum: Ruby on Rails basic operations in rails

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.
21fea09ba0058359363b7bb403cbfb3e?d=identicon&s=25 dave jones (Guest)
on 2006-03-18 22:35
Hi all,
This must be such a beginner's problem, but I can't figure it out.

I'm pulling two integers out of a database, and i want to divide one
value with the other, but i keep getting an error about operating on
strings.
Here's the code -

low_freq = unsorted.last.freq
high_freq = unsorted.first.freq
divider = high_freq / low_freq


In my view, if i display the contents of low_freq or high_freq there is
indeed an integer in there.

Can someone help a newb?

cheers
7cda78d70ab775710f6fa24e0a5b68db?d=identicon&s=25 Emin Hasanov (Guest)
on 2006-03-18 22:46
(Received via mailing list)
try this

low_freq = unsorted.last.freq.to_i
high_freq = unsorted.first.freq.to_i
divider = high_freq / low_freq
21fea09ba0058359363b7bb403cbfb3e?d=identicon&s=25 dave jones (Guest)
on 2006-03-18 23:12
worked like a charm, thanks!

Emin Hasanov wrote:
> try this
>
> low_freq = unsorted.last.freq.to_i
> high_freq = unsorted.first.freq.to_i
> divider = high_freq / low_freq
This topic is locked and can not be replied to.