我正在用JSP开发一个小应用程序,我需要将欧洲应用程序转换成一个国际应用程序(与美国format..etc兼容)。我已经为标记formatNumber 这里创建了模式选项,但它始终取决于应用程序的区域设置。
示例1:
我有一个地区en_US,formatNumber是:
<fmt:formatNumber pattern="#,##0.00" value="${number}"/>结果:15 463 536 640.00
示例2:
我有一个地区es_ES,formatNumber是:
<fmt:formatNumber pattern="#,##0.00" value="${number}"/>结果: 15.463.536.640,00
这是和现场有关的模式!我需要使用逗号和点独立于应用程序区域设置,因为并不总是希望使用地区格式来显示数字。
有什么帮助吗?
发布于 2013-06-03 15:02:49
只需显式地设置区域设置。
<!-- Page's own locale (you should already have that part). -->
<fmt:setLocale value="${user.locale}" />
<fmt:setBundle ... />
... text ...
<!-- Temporarily set to English, format number and then set back to page locale. -->
<fmt:setLocale value="en_US" />
<fmt:formatNumber ... />
<fmt:setLocale value="${user.locale}" />另请参阅:
发布于 2013-06-04 14:36:31
在您自己的标记文件中:
这样的标记文件:
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@attribute name="number" description="The number to format and print." %>
<fmt:setLocale value="en_US"/>
<fmt:formatNumber pattern="#,##0.00" value="${number}"/>
<fmt:setLocale value="${user.locale}"/>或者,如果不想硬编码,可以将模式添加到输入参数中。
发布于 2013-06-03 14:48:12
那DecimalFormat呢
DecimalFormat formatter = new DecimalFormat("###,###,###");https://stackoverflow.com/questions/16899343
复制相似问题