Currency class in java

The Currency class encapsulates information about a currency. It defines no constructors

Demonstrate Currency

import java.util.*;

class CurDemo {

public static void main(String args[]) { Currency c;

c = Currency.getInstance(Locale.US);

System.out.println("Symbol: " + c.getSymbol());

System.out.println("Default fractional digits: " + c.getDefaultFractionDigits());

}

}

Output

Symbol: $
Default fractional digits: 2

The Methods Defined by Currency

MethodDescription 
String getCurrencyCode( )Returns the code (as defined by ISO 4217) that describes 
 the invoking currency. 
   
int getDefaultFractionDigits( )Returns the number of digits after the decimal point that 
 are normally used by the invoking currency. For example, 
 there are 2 fractional digits normally used for dollars. 
   
static CurrencyReturns a Currency object for the locale specified by 
getInstance(Locale localeObj)localeObj. 
static CurrencyReturns a Currency object associated with the currency 
getInstance(String code)code passed in code. 
   
String getSymbol( )Returns the currency symbol (such as $) for the invoking 
 object.  
   
String getSymbol(Locale localeObj)Returns the currency symbol (such as $) for the locale 
 passed in localeObj. 
   
String toString( )Returns the currency code for the invoking object. 

Leave a Comment