使用f:convertNumber时设置小数点分隔符 [英] Set decimal separator when using 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:
On a per-converter basis by the
locale
attribute of the<f:convertNumber>
tag:<f:convertNumber locale="#{bean.locale}" />
- 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
尚不清楚您要定位的语言环境,但是例如对于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" />
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.
这篇关于使用f:convertNumber时设置小数点分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!