如何更改任何一个特定区域设置的货币符号?
How to change the currency symbol for any one specific locale?
我正在使用 jstl 来显示货币值,就像这样...
<fmt:formatNumber value="${sellingPrice}" type="currency"/>
99% 的时间都有效。现在我有一个要求,对于给定的语言环境,客户根本不想显示任何货币符号。
我试过这个:
<fmt:formatNumber currencySymbol="" value="${sellingPrice}" type="currency"/>
...无论语言环境如何,都删除货币符号。
我考虑过使用 spring 消息,如下所示:
<fmt:formatNumber currencySymbol="<spring:message code='myCurrency.symbol' />" value="${sellingPrice}" type="currency"/>
但问题是我需要返回并为我支持的所有其他语言环境创建正确的货币符号,并为可能出现的任何新语言环境添加 spring 消息。 ..
我真正需要的是能够说出类似的话:
if(locale == 'EN_XX') {
currencySymbol=' ';
} else {
// otherwise use whatever the normal currency symbol would be for that locale
}
有什么方法可以覆盖比 JSP 级别低的特定语言环境的默认货币符号吗?我的意思是价值必须来自某个地方,对吗?
我最终创建了自己的扩展 FormatNumberTag 的自定义标签。它计算出正确的语言环境,然后调用 FormatNumberTag.setCurrencySymbol("...");
public class MyFormatNumberTag extends FormatNumberTag {
public MyFormatNumberTag() {
super();
}
//...snip...
@Override
public int doStartTag() throws JspException {
Locale locale = getMyRequestLocale();
if(locale == Locale.EN_GB) setCurrencySymbol("");
return super.doStartTag();
}
}
希望这对某人有所帮助。
我正在使用 jstl 来显示货币值,就像这样...
<fmt:formatNumber value="${sellingPrice}" type="currency"/>
99% 的时间都有效。现在我有一个要求,对于给定的语言环境,客户根本不想显示任何货币符号。
我试过这个:
<fmt:formatNumber currencySymbol="" value="${sellingPrice}" type="currency"/>
...无论语言环境如何,都删除货币符号。
我考虑过使用 spring 消息,如下所示:
<fmt:formatNumber currencySymbol="<spring:message code='myCurrency.symbol' />" value="${sellingPrice}" type="currency"/>
但问题是我需要返回并为我支持的所有其他语言环境创建正确的货币符号,并为可能出现的任何新语言环境添加 spring 消息。 ..
我真正需要的是能够说出类似的话:
if(locale == 'EN_XX') {
currencySymbol=' ';
} else {
// otherwise use whatever the normal currency symbol would be for that locale
}
有什么方法可以覆盖比 JSP 级别低的特定语言环境的默认货币符号吗?我的意思是价值必须来自某个地方,对吗?
我最终创建了自己的扩展 FormatNumberTag 的自定义标签。它计算出正确的语言环境,然后调用 FormatNumberTag.setCurrencySymbol("...");
public class MyFormatNumberTag extends FormatNumberTag {
public MyFormatNumberTag() {
super();
}
//...snip...
@Override
public int doStartTag() throws JspException {
Locale locale = getMyRequestLocale();
if(locale == Locale.EN_GB) setCurrencySymbol("");
return super.doStartTag();
}
}
希望这对某人有所帮助。