2017-10-18 175 views

回答

2

目前(2.3.27)?string.currency总是意味着所提供的默认货币格式由Java。因此,您可以定义自定义格式并使用它,如[email protected](其中currency仅仅是您为该格式提供的名称)而不是改变它。

自定义格式在Java中定义。从手动(http://freemarker.org/docs/pgui_config_custom_formats.html#pgui_config_custom_formats_ex_alias):

// Where you initalize the application-wide Configuration singleton: 
Configuration cfg = ...; 

Map<String, TemplateNumberFormatFactory> customNumberFormats = new HashMap<>(); 
customNumberFormats.put("price", 
     new AliasTemplateNumberFormatFactory(",000.00")); 
customNumberFormats.put("weight", 
     new AliasTemplateNumberFormatFactory("0.##;; roundingMode=halfUp")); 
cfg.setCustomNumberFormats(customNumberFormats); 

,然后在模板:

${[email protected]} 
${[email protected]} 
1

如果你只是想使用的格式

${amount?string["0.##"]} 

或设置number_format

<#setting number_format="0.##"> 

查看所有的freemarker formats options

+0

也许我应该更具体,但我基本上询问如何使用string.currency没有美元符号。你已经显示的方法可以工作,但我试图让我的用户更简单,因为他们不需要知道数字格式的任何内容,只需键入货币即可。这是一个很小的差异,但内部测试表明,对一些人来说理解起来要容易得多;)无论如何,我反正向你提出了这个问题,因为这是一个正确的答案,这是我的错,因为没有更具体。 –

+0

查看https://stackoverflow.com/questions/8658205/format-currency-without-currency-symbol – user7294900

+0

我在看,但它是如何修改内存中的NumberFormat实例,它并不真正适用于FreeMarker哪里您无权访问模板文件中的实例... –

相关问题