Saturday, November 22, 2025
HomeLanguagesJavaCurrency getDefaultFractionDigits() Method in Java with Examples

Currency getDefaultFractionDigits() Method in Java with Examples

The getDefaultFractionDigits() Method of Currency class in Java is used to retrieve or know the fraction digits of this currency which is the default value set by the ISO 4217 currency code.

Syntax:

public int getDefaultFractionDigits()

Parameters: This method does not accept any parameters.

Return Value: This method returns an integer value which is the default fraction digits of the currency.

Exceptions: The method throws Runtime Error if an invalid code is called.

Below program illustrates the working of getDefaultFractionDigits() method:

Program 1:




// Java Code to illustrate
// getDefaultFractionDigits() method
  
import java.util.*;
  
public class Currency_Demo {
    public static void main(String[] args)
    {
  
        // Creating a currency with the code
        Currency curr_ency
            = Currency.getInstance("INR");
  
        // Getting the fraction digit of the currency
        int currency_fracdig
            = curr_ency.getDefaultFractionDigits();
        System.out.println("INR's fractions digits are: "
                           + currency_fracdig);
    }
}


Output:

INR's fractions digits are: 2

Program 2:




// Java Code to illustrate
// getDefaultFractionDigits() method
  
import java.util.*;
  
public class Currency_Demo {
    public static void main(String[] args)
    {
  
        // Creating a currency with the code
        Currency curr_ency
            = Currency.getInstance("JOD");
  
        // Getting the fraction digit of the currency
        int currency_fracdig
            = curr_ency.getDefaultFractionDigits();
        System.out.println("Jordan's fractions digits are: "
                           + currency_fracdig);
    }
}


Output:

Jordan's fractions digits are: 3

Program 3: For an invalid Currency Code.




// Java Code to illustrate
// getDefaultFractionDigits() method
  
import java.util.*;
  
public class Currency_Demo {
    public static void main(String[] args)
    {
  
        try {
            // Creating a currency with the code
            Currency curr_ency
                = Currency.getInstance("JODA");
  
            // Getting the fraction digit of the currency
            int currency_fracdig
                = curr_ency.getDefaultFractionDigits();
            System.out.println("Jordan's fractions digits are: "
                               + currency_fracdig);
        }
        catch (Exception e) {
            System.out.println(e);
        }
    }
}


Output:

java.lang.IllegalArgumentException
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32407 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6785 POSTS0 COMMENTS
Nicole Veronica
11932 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12000 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7168 POSTS0 COMMENTS
Thapelo Manthata
6864 POSTS0 COMMENTS
Umr Jansen
6852 POSTS0 COMMENTS