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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 19:46:57  来源:igfitidea点击:

<fmt:formatNumber in jstl need to $ symbol

javajspstrutsjstl

提问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 currencySymbolattribute.

只需指定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.propertiesand ApplicationResources.en_UK.properties, rather have ApplicationResources.en.propertiesand have a key/value entry that displays only dollar.

例如,如果您有ApplicationResource.en_US.propertiesand ApplicationResources.en_UK.properties,而是有ApplicationResources.en.properties并且有一个只显示美元的键/值条目。

Alternatively, you would set your locale to only en_USbeforedisplaying your currency. Example:

或者,您可以仅en_US显示货币之前将区域设置设置为。例子:

<fmt:setLocale value="en_US"/>
<fmt:formatNumber value="${val}"
                  type="currency"/>