Program to demonstrate java.util.Currency Class : Methods usage in Java
Output of the program :
package com.hubberspot.example; import java.util.Currency; import java.util.Locale; public class CurrencyDemo { public static void main(String[] args) { // Currency.getInstance() creates Currency object for // the locale object passed as a parameter Currency currency = Currency.getInstance(Locale.US); System.out.println("-----------------------------------------"); // currency.getSymbol() returns the currency symbol for the // Currency for which currency object is associated System.out.println("Symbol of the currency : " + currency.getSymbol()); // currency.getDefaultFractionDigits() returns the number of // digits after the decimal point used by invoking currency System.out.println("Default fractional digits : " + currency.getDefaultFractionDigits()); // currency.getCurrencyCode() returns the currency code associated // with the Currency System.out.println("Currency code : " + currency.getCurrencyCode()); // currency.toString() returns the currency code associated // with the Currency System.out.println("Currency code : " + currency.toString()); System.out.println("-----------------------------------------"); currency = Currency.getInstance("GBP"); System.out.println("Currency code : " + currency.getCurrencyCode()); System.out.println("Symbol of the currency : " + currency.getSymbol()); System.out.println("Symbol of the currency : " + currency.getSymbol(Locale.UK)); System.out.println("Currency code : " + currency.toString()); System.out.println("-----------------------------------------"); } }
Output of the program :