java <fmt:formatNumber in jstl 需要 $ 符号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7397253/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
<fmt:formatNumber in jstl need to $ symbol
提问by Santhosh
In our struts app, we have been using <fmt:formatNumber>
is so many places to show currency. By default the tag takes browser setting and showing the currency symbol. If locale is "en_US" showing ($), if "en_UK" showing (euro).
在我们的 struts 应用程序中,我们使用了<fmt:formatNumber>
很多地方来显示货币。默认情况下,标签采用浏览器设置并显示货币符号。如果语言环境是“en_US”显示($),如果“en_UK”显示(欧元)。
But I want to show dollar alone to my whole application. Is there any way to change in single place to reflects.
但我想在我的整个应用程序中单独显示美元。有什么办法可以在单一的地方改变来反映。
Thanks in Advance!!!
提前致谢!!!
回答by BalusC
But I want to show dollar alone to my whole application.
但我想在我的整个应用程序中单独显示美元。
Just specify the currencySymbol
attribute.
只需指定currencySymbol
属性。
<fmt:formatNumber type="currency" currencySymbol="$" value="${product.price}" />
See also:
也可以看看:
回答by Jwalant
In <fmt:setLocale value="en_US"/>
, you can use scope attribute and put value to application. By that way, it will save Locale value to en_US for the whole application.
在 中<fmt:setLocale value="en_US"/>
,您可以使用范围属性并将值赋给应用程序。通过这种方式,它会将整个应用程序的 Locale 值保存到 en_US。
回答by Buhake Sindi
I'm assuming you're using properties file. I would suggest having a properties file based on the language locale instead of country locale.
我假设您正在使用属性文件。我建议使用基于语言区域设置而不是国家/地区区域设置的属性文件。
E.g. If you have ApplicationResource.en_US.properties
and ApplicationResources.en_UK.properties
, rather have ApplicationResources.en.properties
and have a key/value entry that displays only dollar.
例如,如果您有ApplicationResource.en_US.properties
and ApplicationResources.en_UK.properties
,而是有ApplicationResources.en.properties
并且有一个只显示美元的键/值条目。
Alternatively, you would set your locale to only en_US
beforedisplaying your currency. Example:
或者,您可以仅en_US
在显示货币之前将区域设置设置为。例子:
<fmt:setLocale value="en_US"/>
<fmt:formatNumber value="${val}"
type="currency"/>