Java Currency getDefaultFractionDigits() Method



Description

The Java Currency getDefaultFractionDigits() method gets the default number of this currency's fraction digits.

Declaration

Following is the declaration for java.util.Currency.getDefaultFractionDigits() method

public int getDefaultFractionDigits()

Parameters

NA

Return Value

This method returns the default number of fraction digits used with this currency

Exception

NA

Getting Default Fraction Digits of EUR Currency Instance Example

The following example shows the usage of Java Currency getDefaultFractionDigits() method for EUR currency. We've first created a currency object using EUR as currency code and then its default fraction digits are printed.

package com.tutorialspoint;

import java.util.Currency;

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

      // create a currency with EUR code
      Currency curr = Currency.getInstance("EUR");

      System.out.println("Default fraction digits for EUR = " + curr.getDefaultFractionDigits());
   }
}

Output

Let us compile and run the above program, this will produce the following result −

Default fraction digits for EUR = 2

Getting Default Fraction Digits of USD Currency Instance Example

The following example shows the usage of Java Currency getDefaultFractionDigits() method for USD currency. We've first created a currency object using USD as currency code and then its default fraction digits are printed.

package com.tutorialspoint;

import java.util.Currency;

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

      // create a currency with USD code
      Currency curr = Currency.getInstance("USD");

      System.out.println("Default fraction digits for USD = " + curr.getDefaultFractionDigits());
   }
}

Output

Let us compile and run the above program, this will produce the following result −

Default fraction digits for USD = 2

Getting Default Fraction Digits of JPY Currency Instance Example

The following example shows the usage of Java Currency getDefaultFractionDigits() method for JPY currency. We've first created a currency object using JPY as currency code and then its default fraction digits are printed.

package com.tutorialspoint;

import java.util.Currency;

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

      // create a currency with JPY code
      Currency curr = Currency.getInstance("JPY");

      System.out.println("Default fraction digits for JPY = " + curr.getDefaultFractionDigits());
   }
}

Output

Let us compile and run the above program, this will produce the following result −

Default fraction digits for JPY = 0
java_util_currency.htm
Advertisements