使用 Ruby 和 Haml,我有一个属性是成本。我相信(我是 ruby 的新手)它将是一个 Float
目前,下面一行输出我的小数格式,如 4.5 而不是 4.50,这正是我想要的。
%span.value= "£#{event.beers.first.cost)}"
这是我的啤酒类文件。
class Beer
include Mongoid::Document
embeds_many :ratings
field :name, type: String
field :country, type: Country
field :cost, type: Float
field :photos, type: PhotoArray, default: PhotoArray.new
end
最佳答案
如果您使用的是 Rails,您可以使用 number_to_currency helper
关于ruby - 将字符串转换为货币格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8733924/