如何使用没有货币符号或美元符号的货币格式
How to use the currency format without the currency symbol or dollar sign
我有:
${amount?string.currency}
它很好地格式化了我的 BigDecimal,唯一的问题是它包含我不想要的货币符号(美元符号)。如何在不使用 string["0.##"]
?
明确指定数字格式的情况下禁用此功能
如果您只想格式化,请使用
${amount?string["0.##"]}
或设置number_format
:
<#setting number_format="0.##">
查看全部 freemarker formats options
当前 (2.3.27) ?string.currency
始终表示 Java 提供的默认货币格式。因此,与其更改它,不如定义自定义格式并像 amount?string.@currency
一样使用它(其中 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);
然后在模板中:
${product.price?string.@price}
${product.weight?string.@weight}
我有:
${amount?string.currency}
它很好地格式化了我的 BigDecimal,唯一的问题是它包含我不想要的货币符号(美元符号)。如何在不使用 string["0.##"]
?
如果您只想格式化,请使用
${amount?string["0.##"]}
或设置number_format
:
<#setting number_format="0.##">
查看全部 freemarker formats options
当前 (2.3.27) ?string.currency
始终表示 Java 提供的默认货币格式。因此,与其更改它,不如定义自定义格式并像 amount?string.@currency
一样使用它(其中 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);
然后在模板中:
${product.price?string.@price}
${product.weight?string.@weight}