如何在Ruby中添加资金

时间:2016-11-04 23:26:55

标签: ruby-on-rails ruby currency money-rails

让我说我有两个字符串: " $ 7.99" 和 " $ 16.99"

现在,我试图将这些值加在一起得到24.98美元和#34; 这笔钱可能与美元不同,但两个字符串将始终是相同的货币。

我试图使用货币化宝石(https://github.com/RubyMoney/monetize)的组合 和货币宝石(https://github.com/hexorx/currencies

货币宝石包含所有货币信息。

这是我的代码:

require 'monetize'        
require 'currencies'
Money.default_bank = ISO4217::Currency::ExchangeBank.new # from the currencies gem doc
m1 = Monetize.parse "$7.99"
m2 = Monetize.parse "$16.99"
m = m1 + m2
puts m

我收到错误

I18n::InvalidLocale: :en is not a valid locale

即使我加载了货币银行

0 个答案:

没有答案
相关问题