Home » Java programming language

Java Currency getDefaultFractionDigits() Method with Example

Currency Class getDefaultFractionDigits() method: Here, we are going to learn about the getDefaultFractionDigits() method of Currency Class with its syntax and example.
Submitted by Preeti Jain, on February 12, 2020

Currency Class getDefaultFractionDigits() method

  • getDefaultFractionDigits() method is available in java.util package.
  • getDefaultFractionDigits() method is used to get the default fraction digits of this Currency.
  • getDefaultFractionDigits() method is a non-static method, so it is accessible with the class object and if we try to access the method with the class name then we will get an error.
  • getDefaultFractionDigits() method does not throw an exception at the time of returning default fraction digits.

Syntax:

    public int getDefaultFractionDigits();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of this method is int, it returns number of default fraction of this Currency.

Example:

// Java program is to demonstrate the example of
// getDefaultFractionDigits() method of Currency

import java.util.*;

public class GetDefaultFractionDigitsOfCurrency {
    public static void main(String args[]) {
        // Instantiates a currency with INR code
        Currency currency = Currency.getInstance("INR");

        // By using getDefaultFractionDigits() method is 
        // to get the default fraction digits of this Currency
        int curr_def_frac_digits = currency.getDefaultFractionDigits();

        // Display Currency Default Fraction Digits
        System.out.print("currency.getDefaultFractionDigits(): ");
        System.out.println(curr_def_frac_digits);
    }
}

Output

currency.getDefaultFractionDigits(): 2


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.