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.php
This article is contributed by Mohit Gupta. If you like Lazyroar 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 Lazyroar 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.