Skip to content
Related Articles

Related Articles

java.util.Currency methods with example

Improve Article
Save Article
  • Difficulty Level : Basic
  • Last Updated : 25 Nov, 2016
Improve Article
Save Article

This class represents currency. Here, currency is identified by their ISO 4217 currency codes. The purpose of ISO 4217 is to establish internationally recognized codes for the representation of currencies. Currencies can be represented in the code in two ways: a three-letter alphabetic code and a three-digit numeric code.

                        util.Currency methods in Java
               /        /           |            \         \
  getCurrency   getInstance  getDisplayName   getSymbol   getDefaultFractionDigits

Some of the Currency class methods :

  1. getCurrency() : java.util.Currency.getCurrency() method returns ISO 4217 currency code of the passed currency argument.
    Syntax :

    public String getCurrencyCode()
    Return : 
    ISO 4217 currency code of the passed argument.
  2. getInstance() : java.util.Currency.getInstance() method creates currency instance for Currency code.
    Syntax :

    public static Currency getInstance(String cCode)
    Parameter : 
    cCode - ISO 4217 currency code of the passed currency argument
    Return : 
    currency instance for Currency code
  3. getDefaultFractionDigits() : java.util.Currency.getDefaultFractionDigits() method returns default number of argumented currency fraction digits.
    Syntax :

    public int getDefaultFractionDigits()
    Return : 
    returns default number of argumented currency fraction digits.
  4. getDisplayName() : java.util.Currency.getDisplayName() method generates the currency name of the argumented currency code.
    Syntax :

    public string getDisplayName()
    Return : 
    currency name of the argumented currency code
  5. getSymbol() : java.util.Currency.getSymbol() method returns Currency symbol for the argumented currency code. In case, no symbol is returned normal currency code will be returned.
    Syntax :

    public String getSymbol()
    Return : 
    Symbol of the argumented currency code currency code.
  6. Java code explaining getInstance(), getCurrencyCode(),getDefaultFractionDigits(), getDisplayName(), getSymbol() methods in Currency class

    // Java program explaining Currency class methods
    // getInstance(), getCurrencyCode(),getDefaultFractionDigits()
    // getDisplayName(), getSymbol()
    import java.util.*;
    public class NewClass
        public static void main(String[] args)
            // Use of getInstance() method to 'AUD' instance
            Currency c1 = Currency.getInstance("AUD"); //Australian Dollar
            Currency c2 = Currency.getInstance("JPY");  //Japan Yen
            Currency c3 = Currency.getInstance("USD");  //Japan Yen
            // Use of getCurrencyCode() method
            String cCode1 = c1.getCurrencyCode();
            String cCode2 = c2.getCurrencyCode();
            System.out.println("Australian Dollar code : " + cCode1);
            System.out.println("Japan Yen code : " + cCode2);
            // Use of getDefaultFractionDigits() method
            int D1 = c1.getDefaultFractionDigits();
            System.out.println("AUD Fraction digits : " + D1);
            int D2 = c2.getDefaultFractionDigits();
            System.out.println("JPY fraction digits : " + D2);
            // Use of getDisplayName() method
            System.out.println("AUD Display : "+c1.getDisplayName());
            System.out.println("JPY Display : "+c2.getSymbol());
            // Use of getSymbol() method
            System.out.println("JPY Symbol : "+c2.getSymbol());
            System.out.println("USD Symbol : "+c3.getSymbol());



    Australian Dollar code : AUD
    Japan Yen code : JPY
    AUD Fraction digits : 2
    JPY fraction digits : 0
    AUD Display : Australian Dollar
    JPY Display : JPY
    JPY Symbol : JPY
    USD Symbol : $

    Refer the link for list of ISO 4217 Currency Codes :

    This article is contributed by Mohit Gupta. If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

    Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

    My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!