java.util.Currency getSymbol(Locale locale)

Description

The getSymbol(Locale locale) method of Currency class is use to get 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. This method is basically in place to take into consideration different values of each symbol on each Locale, because different countries has different currency symbol that is being used with respect to currency of other countries.

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.

Sample Output

Below is the sample output when you run the above example.

Currency getSymbol(Locale locale) Sample Output