Java Utility Library

Java Currency - getDefaultFractionDigits() Method



The java.util.Currency.getDefaultFractionDigits() method is used to get the default number of fraction digits used with this currency. For example, the default number of fraction digits for the Euro is 2, while for the Japanese Yen it's 0. In the case of pseudo-currencies, such as IMF Special Drawing Rights, -1 is returned.

Syntax

public int getDefaultFractionDigits()

Parameters

No parameter is required.

Return Value

Returns the default number of fraction digits used with this currency.

Exception

NA.

Example:

In the example below, the java.util.Currency.getDefaultFractionDigits() method is used to get the default number of fraction digits used with UK currency.

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //creating a currency for GBP
    Currency Curr = Currency.getInstance("GBP");

    //printing the default number of fraction 
    //digits used with British Pound
    int fraction = Curr.getDefaultFractionDigits();
    System.out.print("Default number of fraction digits used with GBP: ");
    System.out.print(fraction);
  }
}

The output of the above code will be:

Default number of fraction digits used with GBP: 2

❮ Java.util - Currency