使用f:convertNumber时设置小数点分隔符 [英] Set decimal separator when using f:convertNumber

查看:269
本文介绍了使用f:convertNumber时设置小数点分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在我的JSF应用程序上设置默认的十进制分隔符.我有一些<h:inputText>,我需要将其格式化为货币,并带有2个小数位.现在,默认情况下使用的小数点分隔符是逗号,,这在我执行一些保存操作时给了我一个错误.我不知道是否可以设置每次使用<f:convertNumber>标记时都要使用的小数点分隔符.

I want to know how to set the default decimal separator on my JSF application. I have some <h:inputText> that I need to format as money, with 2 decimals. Right now the decimal separator used by default is the comma , and this gives me an error when I do some operations on save. I don't know if I can set the decimal separator to be used everytime that I use <f:convertNumber> tag.

我试图用这个:

<f:convertNumber pattern="########0.00" groupingUsed="false" />

,但仍将逗号设置为小数点分隔符.

but it still sets the comma as decimal separator.

推荐答案

默认的十进制分隔符取决于所使用的语言环境.您可以通过两种方式进行设置:

The default decimal separator depends on the locale used. You can set it in 2 ways:

  1. 通过

  2. 根据每个转换器,通过

  3. On a per-converter basis by the locale attribute of the <f:convertNumber> tag:

    <f:convertNumber locale="#{bean.locale}" />
    

  4. 尚不清楚您要定位的语言环境,但是例如对于en-US的语言环境,对于美元来说,通常使用.作为分数分隔符.所以您需要这样设置:

    It's unclear what locale you're targeting, but the use of . as fraction separator is typical for US dollars with a locale of en-US, for example. So you need to set it as such:

    <f:convertNumber type="currency" currencySymbol="$" locale="en-US" />
    

    它也可以从 bean属性.

    It can also be obtained from a java.util.Locale bean property.

    <f:convertNumber type="currency" currencySymbol="$" locale="#{bean.locale}" />
    

    请注意,我使用的是type="currency",这更具有自我说明性.

    Note that I used type="currency", that's more self-documenting.

    • Does <f:convertNumber> use the right number separator when using patterns to format currency?
    • Localization in JSF, how to remember selected locale per session instead of per request/view

    这篇关于使用f:convertNumber时设置小数点分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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