如何将两个零的 00 打印为整数? [英] How do to print two zero's 00 as an integer?
本文介绍了如何将两个零的 00 打印为整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在研究一些应用学院练习题,但我似乎无法打印两个 00 以进行时间转换.这是我到目前为止所拥有的:
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)
推荐答案
您可以使用 sprintf
:
You can use sprintf
:
sprintf("%02d:%02d", hours, minutes)
或等效的 String#%
"%02d:%02d" % [hours, minutes]
这篇关于如何将两个零的 00 打印为整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文