最佳答案
我想格式化一个包含浮点变量的字符串,其中包含固定数量的小数,我想用这种格式化语法来做:
amount = Math::PI
puts "Current amount: #{amount}"
我想获得 Current amount: 3.14
。
我知道我可以做到
amount = Math::PI
puts "Current amount %.2f" % [amount]
但是我想知道是否可以用 #{}
的方式来做。