Currency class

The Currency class represents a currency.

The methods supported by Currency are shown in the following table.

null

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 Currency getInstance(Locale localeObj)Returns a Currency object for the locale specified by localeObj.
static Currency getInstance(String code)Returns a Currency object associated with the currency 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.

The following program demonstrates Currency.

 
import java.util.Currency;
import java.util.Locale;

public class Main {
  public static void main(String args[]) {
    Currency c = Currency.getInstance(Locale.US);
    System.out.println("Symbol: " + c.getSymbol());
    System.out.println("Default fractional digits: " + c.getDefaultFractionDigits());
  }
}

The output is shown here.


Symbol: $
Default fractional digits: 2
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.