java.util.Currency getSymbol(Locale locale)
Description
It must be noted that when the Locale specified is set to null, a NullPointerException will be thrown.
Method Syntax
public String getSymbol(Locale locale)
Method Argument
Data Type | Parameter | Description |
---|---|---|
Locale | locale | the locale for which a display name for this currency is needed |
Method Returns
The getSymbol(Locale locale) method of Currency class returns the symbol of this currency for the specified locale.
Compatibility
Java 1.4
Java Currency getSymbol(Locale locale) Example
Below is a simple java example on the usage of getSymbol(Locale locale) method of Currency class.
package com.javatutorialhq.java.examples; import static java.lang.System.*; import java.util.Currency; import java.util.Locale; /* * This example source code demonstrates the use of * getSymnbol(Locale locale) method of Currency class. */ public class CurrencyGetSymbolExample { public static void main(String[] args) { // create an instance of Currency class Currency currency = Currency.getInstance("USD"); out.println("Symbol of USD in US:" + currency.getSymbol(Locale.US)); out.println("Symbol of USD in US:" + currency.getSymbol(Locale.JAPAN)); } }
Basically on the above example, we just created a new Currency object with currency code of USD. The currency symbol were extracted for two locale the US and Japan. The two result is different with one another because as what we have discussed already on the earlier section that for each locale, different currency symbol is being used for other country’s currency.