This discussion is archived
2 Replies Latest reply: Jul 22, 2011 7:35 AM by 853982 RSS

Show Currency Symbol on Mac

853982 Newbie
Currently Being Moderated
hii

I have created a java application using swing. It takes the regional setting of system and based on it, it sets the currency symbol with price value. It works fine on Windows and Linux but When I try to run it on Mac, and I changed the regional setting to UK but It shows US currency symbol. Here is my code to get the currency symbol:
DecimalFormatSymbols objDecimalFormat;
objDecimalFormat = new DecimalFormatSymbols();
String mstrCurrSymbol = objDecimalFormat.getCurrencySymbol();
Can anyone please tell me why is it not working on Mac.

Thanks in advance
Sonal
  • 1. Re: Show Currency Symbol on Mac
    StanislavL Pro
    Currently Being Moderated
    What about this?
     NumberFormat.getCurrencyInstance(Locale yourLocaleHere).getCurrency().getSymbol(Locale yourLocaleHere);
  • 2. Re: Show Currency Symbol on Mac
    853982 Newbie
    Currently Being Moderated
    On MAC OS, when the jar file is run, it always detects the Locale as en_US and therefore shows the USD as currency and US English as default language. The code that we are running for testing is:
    Locale lclLanguage;
    lclLanguage = new Locale(Locale.getDefault().getLanguage(),Locale.getDefault().getCountry());
    String strNumberFormat = NumberFormat.getCurrencyInstance(lclLanguage).getCurrency().getSymbol(lclLanguage);
    JOptionPane.showMessageDialog(null, "Number format: " + strNumberFormat);
    ResourceBundle rbLangBundle = null;
     
    JOptionPane.showMessageDialog(null, "Country: " + lclLanguage.getCountry() + "\r\n" + "Display country: " + lclLanguage.getDisplayCountry() + "\r\n" + "Display Language: " + lclLanguage.getDisplayLanguage() +
            "\r\n" + "Display name: " + lclLanguage.getDisplayName() + "\r\n" + "Display variant: " + lclLanguage.getDisplayVariant() + "\r\n" + "ISO3Country: " + lclLanguage.getISO3Country() + "\r\n" +
            "ISO3language: " + lclLanguage.getISO3Language() + "\r\n" + "Language: " + lclLanguage.getLanguage() + "\r\n" + "Variant: " + lclLanguage.getVariant());
    rbLangBundle = ResourceBundle.getBundle("MessagesBundle", lclLanguage);
     
    JOptionPane.showMessageDialog(null, "OS: " + System.getProperty("os.name"));
    DecimalFormatSymbols objDecimalFormat;
    objDecimalFormat = new DecimalFormatSymbols();
     
    JOptionPane.showMessageDialog(null, "Decimal symbol: " + objDecimalFormat.getCurrencySymbol() + "\r\n" +
            "Decimal separator: " + objDecimalFormat.getDecimalSeparator()  + "\r\n" +
            "Grouping seperator: " + objDecimalFormat.getGroupingSeparator() + "\r\n" +
            "Percentage: " + objDecimalFormat.getPercent());
     
    The code works fine on different regional settings on Windows machine. However while testing the same on MAC it will always show US English irrespective of what is set in the preferences section. We have about 10 language files which needs to be used based on the Locale that is set on the client’s machine.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points