How to get currency symbol in java?

To get currency symbol in java , we need a Currency class in Java. Currency class is the utility which represents a currency and comes in java.util package. This class implements Serializable interface. Currencies in java are identified by ISO 4217 currency codes.

Currency class does not provide any constructor we need to get instance of the Currency class using Currency.getInstance() method.

We can get currency symbols using getSymbol() and getSymbol( Locale locale ).

lets see using the example below :



Currency currencySymbol = Currency.getInstance(Locale.US); // Getting currency instance
System.out.println("Currency Symbol of US = " + currencySymbol.getSymbol());//Symbol for mentioned locale


currencySymbol = Currency.getInstance(Locale.CANADA);
System.out.println("Currency Symbol of Canada = " + currencySymbol.getSymbol());

currencySymbol = Currency.getInstance(Locale.JAPAN);
System.out.println("Currency Symbol of Japan = " + currencySymbol.getSymbol());


currencySymbol = Currency.getInstance(new Locale("in", "ID"));
System.out.println("Currency Symbol of India = " + currencySymbol.getSymbol());


Output :

Currency Symbol of US = USD
Currency Symbol of Canada = CAD
Currency Symbol of Japan = JPY
Currency Symbol of India = IDR
Share on Google Plus

About Pranav

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment