w3resource

Java Currency Class: getSymbol() Method

public String getSymbol()

The getSymbol() method is used to get the symbol of a given currency for the default DISPLAY locale.

For example, for the US Dollar, the symbol is "$" if the default 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 is equivalent to calling getSymbol(Locale.getDefault(Locale.Category.DISPLAY)).

Package: java.util

Java Platform: Java SE 8

Syntax:

getSymbol()

Return Value:

the symbol of this currency for the default DISPLAY locale

Return Value Type: String

Example:Java Currency class: getSymbol() Method

import java.util.*;

public class Main {
   public static void main(String args[]) {

     // Create a currency for INR
      Currency cur1 = Currency.getInstance("INR");

      // Get and print the symbol of the currency
      String symbol = cur1.getSymbol();
      System.out.println("Currency symbol is = " + symbol); 
   }
}

Output:

Currency symbol is = INR

public String getSymbol(Locale locale)

Gets 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.

Package: java.util

Java Platform: Java SE 8

Syntax:

getSymbol(Locale locale)

Parameters:

Name Description
locale    the locale for which a display name for this currency is needed

Return Value:

the symbol of this currency for the specified locale

Return Value Type: String

Throws:

NullPointerException - if locale is null

Example:Java Currency class: getSymbol() Method

import java.util.*;

public class Main {
   public static void main(String args[]) {

      // Create a currency for GERMANY locale
      Locale locale = Locale.GERMANY;
      Currency cur1 = Currency.getInstance(locale);

      // Get and print the symbol of the currency
      String symbol = cur1.getSymbol(locale);
      System.out.println("Currency symbol is = " + symbol);
   }
}

Output:

Currency symbol is = €

Java Code Editor:

Previous:getNumericcode Method
Next:toString Method



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/java-tutorial/util/currency/java_currency_getsymbol.php