Home | | Web Programming | Currency - java.util

Chapter: Java The Complete Reference : The Java Library : java.util : More Utility Classes

Currency - java.util

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

Currency

 

The Currency class encapsulates information about a currency. It defines no constructors. The methods supported by Currency are shown in Table 19-11. The following program demonstrates Currency:

 

// Demonstrate Currency.

import java.util.*;

Method : Description

static Set<Currency> getAvailableCurrencies( ) : Returns a set of the supported currencies.

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 two fractional digits normally used for dollars.

String getDisplayName( ) : Returns the name of the invoking currency for the default locale.

String getDisplayName(Locale loc) : Returns the name of the invoking currency for the specified locale.

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.

int getNumericCode( ) : Returns the numeric code (as defined by ISO 4217) for the invoking currency.

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.


Table 19-11   The Methods Defined by Currency

 

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());

 

}

 

}

 

The output is shown here:

 

Symbol: $

 

Default fractional digits: 2


Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
Java The Complete Reference : The Java Library : java.util : More Utility Classes : Currency - java.util |


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2024 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.