java.util

Class Currency

Implemented Interfaces:
Serializable

public final class Currency
extends Object
implements Serializable

Represents a currency. Currencies are identified by their ISO 4217 currency codes. See the ISO 4217 maintenance agency for more information, including a table of currency codes.

The class is designed so that there's never more than one Currency instance for any given currency. Therefore, there's no public constructor. You obtain a Currency instance using the getInstance methods.

Since:
1.4
See Also:
Serialized Form

Method Summary

String
getCurrencyCode()
Gets the ISO 4217 currency code of this currency.
int
getDefaultFractionDigits()
Gets the default number of fraction digits used with this currency.
static Currency
getInstance(String currencyCode)
Returns the Currency instance for the given currency code.
static Currency
getInstance(Locale locale)
Returns the Currency instance for the country of the given locale.
String
getSymbol()
Gets the symbol of this currency for the default locale.
String
getSymbol(Locale locale)
Gets the symbol of this currency for the specified locale.
String
toString()
Returns the ISO 4217 currency code of this currency.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Method Details

getCurrencyCode

public String getCurrencyCode()
Gets the ISO 4217 currency code of this currency.
Returns:
the ISO 4217 currency code of this currency.
Usages and Demos :

View More Examples of getCurrencyCode()
   1: import java.beans.PropertyEditorSupport;
   2: import java.util.Currency;
   3: 
   4:         ...
   5:         try {
   6:             setValue(Currency.getInstance(text));
   7:         } catch (IllegalArgumentException e) {
   8:         ...
   9:     public String getAsText() {
  10:         Currency c = (Currency)getValue();
  11:         if(c == null) {
  12:         ...
  13:         else {
  14:             return c.getCurrencyCode();

View Full Code Here
   1: import java.text.NumberFormat;
   2: import java.util.Currency;
   3: import java.util.Locale;
   4:         ...
   5:     private long amount;
   6:     private Currency currency;
   7: 
   8:         ...
   9:         nf.setMaximumFractionDigits(currency.getDefaultFractionDigits());
  10:         return currency.getCurrencyCode() + " " + nf.format(getDecimalAmount());
  11:     }

View Full Code Here

getDefaultFractionDigits

public int getDefaultFractionDigits()
Gets the default number of fraction digits used with this currency. For example, the default number of fraction digits for the Euro is 2, while for the Japanese Yen it's 0. In the case of pseudo-currencies, such as IMF Special Drawing Rights, -1 is returned.
Returns:
the default number of fraction digits used with this currency
Usages and Demos :

View More Examples of getDefaultFractionDigits()
   1: import java.text.NumberFormat;
   2: import java.util.Currency;
   3: import java.util.Locale;
   4:         ...
   5:     private long amount;
   6:     private Currency currency;
   7: 
   8:         ...
   9:         Validate.notNull(currency, "Currency cannot be null");
  10:         double centFactor = Math.pow(10, currency.getDefaultFractionDigits());
  11:         this.amount = Math.round(amount * centFactor);
  12:         ...
  13:     public BigDecimal getDecimalAmount() {
  14:         return BigDecimal.valueOf(amount, currency.getDefaultFractionDigits());

View Full Code Here

getInstance

public static Currency getInstance(String currencyCode)
Returns the Currency instance for the given currency code.
Parameters:
currencyCode - the ISO 4217 code of the currency
Returns:
the Currency instance for the given currency code
Throws:
NullPointerException - if currencyCode is null
IllegalArgumentException - if currencyCode is not a supported ISO 4217 code.
Usages and Demos :

View More Examples of getInstance(String currencyCode)
   1: 
   2: import java.util.Currency;
   3: 
   4:         ...
   5:     public boolean canConvert(Class type) {
   6:         return type.equals(Currency.class);
   7:     }
   8:         ...
   9:     public Object fromString(String str) {
  10:         return Currency.getInstance(str);
  11:     }

View Full Code Here
   1:             if (column == 1)
   2:                 return "Currency Code";
   3:             else
   4:         ...
   5:                 return "Currency Symbol";
   6:          }
   7:         ...
   8:                     if (col == 1)
   9:                         return Currency.getInstance(locales [row])
  10:                                        .getCurrencyCode ();
  11:         ...
  12:                     else
  13:                         return Currency.getInstance(locales [row])

View Full Code Here
   1: import java.text.NumberFormat;
   2: import java.util.Currency;
   3: import java.util.Locale;
   4:         ...
   5:         if (code != null) {
   6:           Currency currency = Currency.getInstance(code);
   7:         ...
   8:           formatter.setCurrency(currency);
   9:         }

View Full Code Here
   1: import java.text.NumberFormat;
   2: import java.util.Currency;
   3: import java.util.Locale;
   4:         ...
   5:         if (code != null) {
   6:           Currency currency = Currency.getInstance(code);
   7:         ...
   8:           formatter.setCurrency(currency);
   9:         }

View Full Code Here
   1: 
   2:     public java.util.Currency getItemPriceCurrency() {
   3:         ...
   4:     return java.util.Currency.getInstance(getTheItemPrice().getPriceAmount().getAmountCurrencyID());
   5:     }
   6: 
   7:     public int getItemQuantity() {

View Full Code Here

getInstance

public static Currency getInstance(Locale locale)
Returns the Currency instance for the country of the given locale. The language and variant components of the locale are ignored. The result may vary over time, as countries change their currencies. For example, for the original member countries of the European Monetary Union, the method returns the old national currencies until December 31, 2001, and the Euro from January 1, 2002, local time of the respective countries.

The method returns null for territories that don't have a currency, such as Antarctica.

Parameters:
locale - the locale for whose country a Currency instance is needed
Returns:
the Currency instance for the country of the given locale, or null
Throws:
NullPointerException - if locale or its country code is null
IllegalArgumentException - if the country of the given locale is not a supported ISO 3166 country code.
Usages and Demos :

View More Examples of getInstance(Locale locale)
   1: 
   2: import java.util.Currency;
   3: 
   4:         ...
   5:     public boolean canConvert(Class type) {
   6:         return type.equals(Currency.class);
   7:     }
   8:         ...
   9:     public Object fromString(String str) {
  10:         return Currency.getInstance(str);
  11:     }

View Full Code Here
   1:             if (column == 1)
   2:                 return "Currency Code";
   3:             else
   4:         ...
   5:                 return "Currency Symbol";
   6:          }
   7:         ...
   8:                     if (col == 1)
   9:                         return Currency.getInstance(locales [row])
  10:                                        .getCurrencyCode ();
  11:         ...
  12:                     else
  13:                         return Currency.getInstance(locales [row])

View Full Code Here
   1: import java.text.NumberFormat;
   2: import java.util.Currency;
   3: import java.util.Locale;
   4:         ...
   5:         if (code != null) {
   6:           Currency currency = Currency.getInstance(code);
   7:         ...
   8:           formatter.setCurrency(currency);
   9:         }

View Full Code Here
   1: import java.text.NumberFormat;
   2: import java.util.Currency;
   3: import java.util.Locale;
   4:         ...
   5:         if (code != null) {
   6:           Currency currency = Currency.getInstance(code);
   7:         ...
   8:           formatter.setCurrency(currency);
   9:         }

View Full Code Here
   1: 
   2:     public java.util.Currency getItemPriceCurrency() {
   3:         ...
   4:     return java.util.Currency.getInstance(getTheItemPrice().getPriceAmount().getAmountCurrencyID());
   5:     }
   6: 
   7:     public int getItemQuantity() {

View Full Code Here

getSymbol

public String getSymbol()
Gets the symbol of this currency for the default locale. For example, for the US Dollar, the symbol is "$" if the default locale is the US, while for other locales it may be "US$". If no symbol can be determined, the ISO 4217 currency code is returned.
Returns:
the symbol of this currency for the default locale
Usages and Demos :

View More Examples of getSymbol()
   1: import java.io.Serializable;
   2: import jp.ujihara.java.util.Currency;
   3: import jp.ujihara.java.util.Locale;
   4:         ...
   5: 
   6:   public Currency getCurrency ()
   7:   {
   8:         ...
   9:     return Currency.getInstance (currencySymbol);
  10:   }
  11:         ...
  12:   {
  13:     setCurrencySymbol (currency.getSymbol());

View Full Code Here

getSymbol

public String getSymbol(Locale locale)
Gets the symbol of this currency for the specified locale. For example, for the US Dollar, the symbol is "$" if the specified locale is the US, while for other locales it may be "US$". If no symbol can be determined, the ISO 4217 currency code is returned.
Parameters:
locale - the locale for which a display name for this currency is needed
Returns:
the symbol of this currency for the specified locale
Throws:
NullPointerException - if locale is null

toString

public String toString()
Returns the ISO 4217 currency code of this currency.
Overrides:
toString in interface Object
Returns:
the ISO 4217 currency code of this currency
Usages and Demos :

View More Examples of toString()
   1: 
   2:         changes.add(new OntologyChangeEvent(KAON2Manager.factory().dataPropertyMember(price,smart,new Currency(9000,"EUR")),OntologyChangeEvent.ChangeType.ADD));
   3: 
   4:         ...
   5:             Object[] tupleBuffer=inUSD.tupleBuffer();
   6:             System.out.println("'"+tupleBuffer[0].toString()+"' costs "+tupleBuffer[1].toString());
   7:             inUSD.next();
   8:         ...
   9: 
  10:     protected static class Currency {
  11:         protected final double m_amount;
  12:         ...
  13: 
  14:         public Currency(double amount,String code) {

View Full Code Here