Java Currency getSymbol Example
Currency class getSymbol() method example. This example shows you how to use getSymbol() method.
Syntax is : public String getSymbol(Locale locale)
Method returns the symbol of this currency for the specified locale. For example return symbol "$" if the specified locale is the US. If no symbol can be determined, the ISO 4217 currency code is returned.
Here is the code.
/**
* @(#) GetSymbol2Currency.java
* A class representing use of method getSymbol() of Currency class
in java.util Package.
* @Version 21-May-2008
* @author Rose India Team
*/
import java.util.*;
class GetSymbol2Currency {
public static void main( String args[] ){
// This is field of Locale class <public static final Locale US>
Locale locale = Locale.US;
/* There is no default constructor available so here getInstance()
method used to create object of Currency class. */
Currency curr = Currency.getInstance(locale);
// Method call with argument of locale type.
String symbol = curr.getSymbol(locale);
System.out.println( "Currency symbol for the given Locale is = "+symbol);
}
} |
Output of the program..
| Currency symbol for the given Locale is = $ |
|