2017-10-18 173 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哪裏您無權訪問模板文件中的實例... –

相關問題