Java Utility Library

Java Currency - getSymbol() Method



The java.util.Currency.getSymbol() method is used 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.

Syntax

public String getSymbol(Locale locale)

Parameters

locale Specify the locale for which a display name for this currency is needed.

Return Value

Returns the symbol of this currency for the specified locale.

Exception

Throws NullPointerException, if locale is null.

Example:

In the example below, the java.util.Currency.getSymbol() method is used to get the symbol of the currency for the specified locale.

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //creating a currency for UK locale
    Locale locale = Locale.UK;
    Currency Curr = Currency.getInstance(locale);

    //getting and printing the currency symbol
    String symbol = Curr.getSymbol(locale);
    System.out.println("Currency symbol is: " + symbol);
  }
}

The output of the above code will be:

Currency symbol is: £

❮ Java.util - Currency