convert seconds to minutes in ruby

To convert seconds to minutes in Ruby, you could use the following code:

main.rb
seconds = 300
minutes = seconds / 60.0
puts minutes # Output: 5.0
66 chars
4 lines

In this code, we first define the number of seconds we want to convert to minutes, which in this example is 300. We then divide this value by 60.0 to get the number of minutes. The use of 60.0 instead of 60 is important, because otherwise integer division would be performed, which would result in an incorrect answer. Finally, we print out the result using the puts method.

You can substitute the number 300 with any number of seconds that you want to convert to minutes.

gistlibby LogSnag