8

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.

I tried to use this:

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

but it still sets the comma as decimal separator.

4

1 回答 1

15

默认的小数点分隔符取决于使用的语言环境。您可以通过 2 种方式进行设置:

  1. 根据标签的locale属性,按浏览次数计算:<f:view>

     <f:view locale="#{bean.locale}">
    
  2. 根据标签的locale属性在每个转换器的基础上:<f:convertNumber>

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

目前尚不清楚您的目标是什么语言环境,但是对于例如.语言环境为 的美元来说,使用分数分隔符是典型的en-US。所以你需要这样设置:

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

它也可以从java.util.Localebean 属性中获得。

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

请注意,我使用type="currency"了 ,这是更多的自我记录。

也可以看看:

于 2011-10-22T00:48:48.783 回答