如果採取貨幣寶石一看,在/config/currency_iso.json
{
"Jpy": {
"priority": 6,
"iso_code": "JPY",
"name": "Japanese Yen",
"symbol": "¥",
"alternate_symbols": ["円", "圓"],
"subunit": null,
"subunit_to_unit": 1,
"symbol_first": true,
"html_entity": "¥",
"decimal_mark": ".",
"thousands_separator": ",",
"iso_numeric": "392",
"smallest_denomination": 1
}
}
你會看到
"subunit_to_unit": 1
所以在這種情況下,你應該重寫日元和新臺幣貨幣與
"subunit_to_unit": 100
這是我在/config/initializers/money.rb下的示例代碼
Money::Currency.register({
"priority": 6,
"iso_code": "JPY",
"name": "Japanese Yen",
"symbol": "¥",
"alternate_symbols": ["円", "圓"],
"subunit": "Sen",
"subunit_to_unit": 100,
"symbol_first": true,
"html_entity": "¥",
"decimal_mark": ".",
"thousands_separator": ",",
"iso_numeric": "392",
"smallest_denomination": 1
})
您可以在這裏添加更多貨幣。希望這對你有所幫助。
您能否將用戶提供金額乘以100? –
所以我必須寫'if else'條件,如果用戶選擇USD或TWD,我應該乘以100,如果'JPY'我不需要乘以'100'。這些會增加我的應用程序的複雜性。容易產生新的錯誤,我發現是否有更優雅的解決方案T_T – newBike