Currently I\'m having a problem displaying formatted decimals. In my local machine I have a decimal value: 0.002100000000 stored in database.
The DecimalFormat pattern is, as its name (and javadoc) says, a pure pattern. In this pattern, the ,
represents the grouping separator and the .
represents the decimal separator. It's exactly like as that MMM
represents the abbreviated month in SimpleDateFormat (note that it doesn't return MMM
as month during formatting, but just like May
or e.g. Mei
depending on the locale).
The actual character being used as grouping separator and decimal separator (and the actual text being used as abbreviated month) during formatting depends on the locale, exactly as you observed. This is correct behavior. When you don't explicitly specify the locale during creating the DecimalFormat
(or SimpleDateFormat
), then the default locale as available by Locale#getDefault() will be assumed. You should actually be specifying the UIViewRoot#getLocale()
or maybe a fixed locale like Locale.ENGLISH
if your JSF web application is not localized for some unclear reason.
Please also note that DecimalFormat
is (like SimpleDateFormat
) not threadsafe (check the "Synchronization" section in the javadoc). You should not be creating it in class/instance scope, but in thread local scope (i.e. in the very same method block as where you need it).
I have only no idea which BigDecimalConverter
you're using, the standard JSF one doesn't have a getDecimalFormat()
method, so I can't give a more concrete example of the proper approach.