我正在为SpreeCommerce 2.1.3构建一个网站,我一直试图找出如何正确格式化价格。
货币是DKK(丹麦克朗),我正在寻找以下内容:
Spree格式化我的价格:
所以有两个问题:
我如何做到这一点?
以下是 config / initializers / spree.rb 的配置:
Spree.config do |config|
# [...]
config.currency = "DKK"
config.currency_symbol_position = "before"
config.currency_decimal_mark = ","
config.currency_thousands_separator = "."
end
解决方案:
1)我将这个装饰器添加到Spree :: Money(替换,00 with, - ):
Spree::Money.class_eval do
def to_s
formatted = @money.format(@options)
formatted.gsub(/,00$/, ",-")
end
def to_html(options = { :html => true })
to_s
end
end
2)我在初始化程序中配置了丹麦货币(在kr之后添加空格):
Money::Currency.register({
:priority => 1,
:iso_code => "DKK",
:iso_numeric => "208",
:name => "Danish krone",
:symbol => "kr. ",
:subunit => "Øre",
:subunit_to_unit => 100,
:separator => ".",
:delimiter => ","
})