默认情况下,金钱节省了几美分的价值,并像price_cents:integer一样创建了迁移。我需要保存并计算小美元(货币的1/1000)的值。
我自己不注册货币。我使用gem google_currency来获取当前的汇率。
如何为所有货币值设置精度1/1000?
* rails (4.2.1)
* money (6.5.1)
* money-rails (1.4.1)
* google_currency (3.2.0)发布于 2015-05-22 20:56:18
根据documentation,您可以注册自己的子单元:
curr = {
:priority => 1,
:iso_code => "USD",
:iso_numeric => "840",
:name => "United States Dollar",
:symbol => "$",
:subunit => "Minidollar",
:subunit_to_unit => 1000,
:separator => ".",
:delimiter => ","
}
Money::Currency.register(curr)Google Currency只是扩展了Money::Bank::VariableExchange,所以现在你可以这样做来创建一个1美元的商品,并获得欧元的价值:
money = Money.new(10_00, "USD") # this is in "minidollars"
money.exchange_to(:EUR)https://stackoverflow.com/questions/30393557
复制相似问题