java.util.Currency methods with example - GeeksforGeeks

25 Nov, 2016
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 :
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.
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
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.
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
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.
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);        System.out.println("");          // 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);        System.out.println("");          // Use of getDisplayName() method        System.out.println("AUD Display : "+c1.getDisplayName());        System.out.println("JPY Display : "+c2.getSymbol());        System.out.println("");          // Use of getSymbol() method        System.out.println("JPY Symbol : "+c2.getSymbol());        System.out.println("USD Symbol : "+c3.getSymbol());      }}Output: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 :http://www.xe.com/iso4217.phpThis article is contributed by Mohit Gupta. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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_upSave
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.

public String getCurrencyCode()
Return : 
ISO 4217 currency code of the passed argument.

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

public static Currency getInstance(String cCode)
Parameter : 
cCode - ISO 4217 currency code of the passed currency argument
Return : 
currency instance for Currency code

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.

public int getDefaultFractionDigits()
Return : 
returns default number of argumented currency fraction digits.

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

public string getDisplayName()
Return : 
currency name of the argumented currency code

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.
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);        System.out.println("");          // 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);        System.out.println("");          // Use of getDisplayName() method        System.out.println("AUD Display : "+c1.getDisplayName());        System.out.println("JPY Display : "+c2.getSymbol());        System.out.println("");          // Use of getSymbol() method        System.out.println("JPY Symbol : "+c2.getSymbol());        System.out.println("USD Symbol : "+c3.getSymbol());      }}Output: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 :http://www.xe.com/iso4217.phpThis article is contributed by Mohit Gupta. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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_upSave
public String getSymbol()
Return : 
Symbol of the argumented currency code currency code.

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);        System.out.println("");          // 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);        System.out.println("");          // Use of getDisplayName() method        System.out.println("AUD Display : "+c1.getDisplayName());        System.out.println("JPY Display : "+c2.getSymbol());        System.out.println("");          // Use of getSymbol() method        System.out.println("JPY Symbol : "+c2.getSymbol());        System.out.println("USD Symbol : "+c3.getSymbol());      }}
Output:
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 :http://www.xe.com/iso4217.php
This article is contributed by Mohit Gupta. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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.
Java-Library
Java
Java
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Object Oriented Programming (OOPs) Concept in Java
HashMap in Java with Examples
Stream In Java
Interfaces in Java
How to iterate any Map in Java
ArrayList in Java
Initialize an ArrayList in Java
Stack Class in Java
Singleton Class in Java
Multidimensional Arrays in Java