无法在ruby和money gem中输出货币
如果我运行此代码:无法在ruby和money gem中输出货币,ruby,Ruby,如果我运行此代码: require "money" price1 = Money.new(100) price2 = Money.new(2000) total = price1 + price2 puts total 我收到一个I18n::InvalidLocale错误: 如何避免此问题?尝试以下方法: require "money" price1 = Money.new(100) price2 = Money.new(2000) total = price1 + price2
require "money"
price1 = Money.new(100)
price2 = Money.new(2000)
total = price1 + price2
puts total
我收到一个I18n::InvalidLocale错误:
如何避免此问题?尝试以下方法:
require "money"
price1 = Money.new(100)
price2 = Money.new(2000)
total = price1 + price2
puts "#{total.fractional} #{total.currency}"
gem使用的钱。您可以添加有效的区域设置或禁用I18n:
require 'money'
Money.new(100).format #=> I18n::InvalidLocale: :en is not a valid locale
Money.use_i18n = false
Money.new(100).format #=> "$1.00"
谢谢你,这很有效!!!据我所知,2100是以美分为单位的,对吗?????我如何使它以美元输出例如;2100@DenieallJoenethen我想是这样的:总计。如果这个答案对你有帮助,请记下来。这正是我要找的。非常感谢。
require "money"
price1 = Money.new(100)
price2 = Money.new(2000)
total = price1 + price2
puts "#{total} #{total.currency}"
require 'money'
Money.new(100).format #=> I18n::InvalidLocale: :en is not a valid locale
Money.use_i18n = false
Money.new(100).format #=> "$1.00"