我是红宝石的初学者,所以它是新手的问题。
我正在尝试使用如下所示的float值连接字符串,然后将其打印出来。
puts " Total Revenue of East Cost: " + total_revenue_of_east_cost
total_revenue_of_east_cost是一个保存浮点值的变量,我如何使它打印?
Answers:
我喜欢(有关详细信息,请参见类字符串%):
puts " Total Revenue of East Coast: " + "%.2f" % total_revenue_of_east_coast
气泡实例
(1..100).each do |i| puts "indice #{i} " end