Search code examples
androidcurrencysymbolscurrency-formatting

Currency Symbol and Code dynamic


I am implementing amount of different countries where I need to show Currency symbols. I will get dynamic Currency Code like "USD, "EURO","INR" which are returned by Google API, according to these code I have to display their respective Currency Symbol like $, etc., I have done following :

MyCurrency[] MyCurrencyAll ={   new MyCurrency("$", "dollar sign"),   new MyCurrency("¢", "cent sign"),   new MyCurrency("£", "pound sign"),   new MyCurrency("¤", "currency sign")};

But these dollar sign , pound sign will not be taken by Localisation.

So what can be done to do this as I have tried localisation also but there also I am getting error.

PLease help me out.


Solution

  • try this code to get currency symbol

      public static String getCurrencySymbol(String countryCode) {
            // Locale locale = new Locale("", countryCode);
            Currency currency = Currency.getInstance(countryCode);
            String symbol = currency.getSymbol();
            return symbol;
        }
    

    for more reference see this http://docs.oracle.com/javase/6/docs/api/java/util/Currency.html#getSymbol()