Pin It

java.util.Currency Class : Methods Usage in Java

Program to demonstrate java.util.Currency Class : Methods usage in Java

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 :



Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Related Posts Plugin for WordPress, Blogger...

Post your related queries below ...

comments powered by Disqus
Powered by Blogger.
 
© 2012 Learn Java by Examples Template by Hubber Spot