Menu
Topics Index
...
`


More Utility Classes >
Siva Nookala - 15 Apr 2016
The Currency class encapsulates information about a currency. It defines no constructors.

The methods supported by Currency are shown below.

Method Description
static Set<Currency> getAvailableCurrencies() Returns a set of available currencies.
String getCurrencyCode() Returns the ISO 4217 currency code of the invoking currency.
String getDisplayName() Returns the name that is suitable for displaying this currency for the default locale.
String getDisplayName(Locale locale) Gets the name that is suitable for displaying this currency for the specified locale.
static Currency getInstance(Locale locale) Returns the Currency instance for the country of the given locale.
static Currency getInstance(String currencyCode) Returns the Currency instance for the given currency code.
String getSymbol() Gets the symbol of this currency for the default locale.
String getSymbol(Locale locale) Returns the symbol of this currency for the specified locale.

Example Program :
CurrencyDemo
import java.util.*;

class CurrencyDemo
{
    public static void main(String arg[])
    {
        Currency currency = Currency.getInstance(Locale.US);
        System.out.println( "Currency : " + currency.getDisplayName());
        System.out.println("Symbol : " + currency.getSymbol());    
    }
}
OUTPUT

Currency : US Dollar
Symbol : $

DESCRIPTION

In the above program we are creating a currency object for Locale US and displaying it name and it's symbol.

THINGS TO TRY
  • Create a currency object for Locale CHINA display the currency name and symbol
  • Create a currency object for Locale GERMANY display the currency name and symbol

0
Wrong
Score more than 2 points

© meritcampus 2016 - 2017

All Rights Reserved.