Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在ruby和money gem中输出货币_Ruby - Fatal编程技术网

无法在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"