用于JSP自定义模式的JSTL formatNumber,与语言无关 [英] JSTL formatNumber for JSP custom pattern independent from language

查看:184
本文介绍了用于JSP自定义模式的JSTL formatNumber,与语言无关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JSP开发一个小应用程序,我需要将欧洲应用程序转换为国际应用程序(与US format..etc兼容)。我已经为标签 formatNumber 创建了模式选项这里但它总是取决于您的应用程序的区域设置。

I'm developing a little app with JSP and I need to convert the European app to an international one (compatible with US format..etc). I've founded the pattern option for tag formatNumber here but it always depends on locale of your application.

示例1:

我有一个区域设置 en_US ,而formatNumber是:

I have a locale en_US and the formatNumber is:

 <fmt:formatNumber pattern="#,##0.00" value="${number}"/>

结果: 15,463,536,640.00

Result: 15,463,536,640.00

示例2:

我有一个区域设置 es_ES ,而formatNumber是:

I have a locale es_ES and the formatNumber is:

 <fmt:formatNumber pattern="#,##0.00" value="${number}"/>

结果: 15.463.536.640,00

Result: 15.463.536.640,00

这就是那种与语言环境有关的模式!我需要独立于应用程序区域设置使用逗号和点,因为并不总是希望使用区域设置格式来显示数字。

The thing it's that pattern it's related to locale! I need to use commas and dots independently from application locale because not always want to use locale format for show the numbers.

任何帮助?

推荐答案

只需明确设置区域设置。

Just explicitly set the locale.

<!-- 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}" />



参见:




  • 服务器设置正在覆盖DecimalFormat

  • See also:

    • DecimalFormat is being overridden by server settings
    • 这篇关于用于JSP自定义模式的JSTL formatNumber,与语言无关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆