我正在为SpreeCommerce 2.1.3建立一个网站,我一直试图找出如何正确格式化价格.
货币是DKK(丹麦克朗),我正在寻找以下内容:
> 1000 => KR. 1.000, –
> 1000.50 => KR. 1.000,50
Spree格式化我的价格如下:
> 1000 => kr.1.000,00
> 1000.50 => kr.1.000,50
所以有两个问题:
>我需要一个kr之间的空间.和价格.
>当没有任何小数时,我希望小数呈现为, – (例如:1.000, – )
我该如何做到这一点?
这是来自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 => ","
})
最佳答案 您可以根据需要自定义
https://github.com/spree/spree/blob/master/core/lib/spree/money.rb.