如果我运行此代码:
require "money"
price1 = Money.new(100)
price2 = Money.new(2000)
total = price1 + price2
puts total
我收到I18n::InvalidLocale
错误:
[path to ruby]/gems/i18n-0.7.0/lib/i18n.rb:284:in `enforce_available_locales!': :en is not a valid locale (I18n::InvalidLocale)
我该怎么做才能避免这个问题?
答案 0 :(得分:3)
money gem使用I18n。您可以添加有效的区域设置或禁用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"
答案 1 :(得分:0)
试试这个:
require "money"
price1 = Money.new(100)
price2 = Money.new(2000)
total = price1 + price2
puts "#{total.fractional} #{total.currency}"
答案 2 :(得分:0)
require "money"
price1 = Money.new(100)
price2 = Money.new(2000)
total = price1 + price2
puts "#{total} #{total.currency}"