I'm working on some app academy practice questions and I can't seem to print two 00's for my time conversion. Here's what I have so far:
def time_conversion(minutes)
hours = minutes/60
if minutes%60 < 10
minutes = minutes%60
elsif minutes%60 > 10
minutes = minutes%60
elsif minutes%60 == 0
minutes = 00
end
return "#{hours}:#{minutes}"
end
time_conversion(360)
You can use sprintf
:
sprintf("%02d:%02d", hours, minutes)
or the equivalent String#%
"%02d:%02d" % [hours, minutes]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With