You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Travis Reeder <tr...@ecommstats.com> on 2005/01/31 01:27:00 UTC

Currency converter and default locale

I have been wondering for a while why when I use the currency converter, 
it outputs some strange currency symbol and I ran some tests and it 
looks to me like MyFaces isn't initializing the Locale properly.

This is what I see: ¤98.20

When I use:
<h:outputText value="#{bucket.revenue}"><f:convertNumber 
type="currency"/></h:outputText>

And there is no locale configuration in faces-config or anything so I 
would expect it to do the conversion based on my machines locale so I'd 
expect: $98.20.

To test this I tried this:
Locale l = FacesContext.getCurrentInstance().getViewRoot().getLocale();
System.out.println("Locale: " +  l + " - " + l.getCountry());

Which outputs: Locale: en -

And wrote a little test program:

public class CurrencyFormatLocaleTest {
    public static void main(String[] args) {
        double currency = 6.99;
        NumberFormat nf = NumberFormat.getCurrencyInstance();
        System.out.println("NumberFormat.getCurrencyInstance(): " + 
nf.format(currency));
        Locale locale = new Locale("en");
        nf = NumberFormat.getCurrencyInstance(locale);
        System.out.println("NumberFormat.getCurrencyInstance(en): " + 
nf.format(currency));
        locale = new Locale("en", "US");
        nf = NumberFormat.getCurrencyInstance(locale);
        System.out.println("NumberFormat.getCurrencyInstance(en, US): " 
+ nf.format(currency));
        locale = Locale.getDefault();
        nf = NumberFormat.getCurrencyInstance(locale);
        
System.out.println("NumberFormat.getCurrencyInstance(Locale.getDefault()): 
" + nf.format(currency));

    }
}

Which returns the following:
NumberFormat.getCurrencyInstance(): $6.99
NumberFormat.getCurrencyInstance(en): ¤6.99
NumberFormat.getCurrencyInstance(en, US): $6.99
NumberFormat.getCurrencyInstance(Locale.getDefault()): $6.99

So the language is set properly, but the country is not set and 
Locale.getDefault() is NOT being used. 

Anyone else seeing this?

-- 
Travis Reeder
Ecommstats Web Analytics
www.ecommstats.com