It's important to know and understand that the <f:convertNumber>
tag uses DecimalFormat
under the covers. You can find all pattern characters in its javadoc.
It seems that you expected that the DecimalFormat
pattern characters ,
and .
are also actually used in the final format. This is untrue. It are really merely pattern characters (like as d
, M
, y
, etc as used bySimpleDateFormat
). Basically, the pattern character ,
tells DecimalFormat
to print the "grouping separator" as specified by the given locale and, equivalently, the pattern character .
tells DecimalFormat
to print the "decimal separator" as specified by the given locale.
In effects, the actual character being printed depends on the given locale. For English locale (locale="en"
), the "grouping separator" being printed is just coincidentally also ,
, but for German locale (locale="de"
) the "grouping separator" being printed is indeed .
.
Unrelated to the concrete problem, the type
attribute of <f:convertNumber>
has totally no effect if the pattern
attribute is specified. The type
attribtue is basically superfluous in this example and can safely be removed without any side effects.
If you remove the pattern
attribute, then it'll actually be used and you'll see that the default pattern for a currency is being used, which is same as ¤#,##0.00
for English locale and ¤ #,##0.00
for German locale. Also note that the pattern character representing the currency symbol is not $
, but ¤
. The currency symbol can be set separately via currencySymbol
attribute. So the correct approach for currencies would be:
<f:convertNumber type="currency" locale="#{userSession.locale}" currencySymbol="$" />
Again, see the DecimalFormat
javadoc as linked before.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…