Java Currency.getSymbol(Locale locale) Method

 Posted On  | Yashwant Chavan 

In this tutorial, You will learn about Java Currency.getSymbol(Locale locale) Method. Which returns 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

Gets the symbol of this currency for the specified locale.

String java.util.Currency.getSymbol(Locale locale)

Parameters

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

Return

return the symbol of this currency for the specified locale.

Exception

throws NullPointerException if locale is null.

Java Currency.getSymbol(Locale locale) example

Refer below steps

  • Create Currency instance using Currency.getInstance(Locale locale) method.
  • In first scenario, We have used Currency.getSymbol() method. Which returns the symbol of this currency for the default DISPLAY locale.
  • And in second scenario, We have used Currency.getSymbol(Locale locale) - method. Which returns the currency symbol for the specified locale.
package com.technicalkeeda.app;

import java.util.Currency;
import java.util.Locale;

public class JavaCurrencySymbol {

    public static void main(String[] args) {

        Currency us = Currency.getInstance(Locale.US);
        System.out.println("Currency Symbol:- " + us.getSymbol());
        System.out.println("Currency Symbol With Local:- " + us.getSymbol(Locale.US));

        Currency uk = Currency.getInstance(Locale.UK);
        System.out.println("\nCurrency Symbol:- " + uk.getSymbol());
        System.out.println("Currency Symbol With Local:- " + uk.getSymbol(Locale.UK));

        Currency germany = Currency.getInstance(Locale.GERMANY);
        System.out.println("\nCurrency Symbol:- " + germany.getSymbol());
        System.out.println("Currency Symbol With Local:- " + germany.getSymbol(Locale.GERMANY));

    }
}

Output

Currency Symbol:- USD
Currency Symbol With Local:- $

Currency Symbol:- GBP
Currency Symbol With Local:- £

Currency Symbol:- EUR
Currency Symbol With Local:- €


© technicalkeeda.com 2017

 |  Find us on Google+ |  Rss Feed

Loaded in 0.0355 seconds.