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); } } |
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); } } |
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); } } } |
java.lang.IllegalArgumentException
Recommended Posts:
- Currency getCurrencyCode() Method in Java with Examples
- Currency toString() Method in Java with Examples
- Currency getInstance() Method in Java with Examples
- Currency getSymbol Method in Java with Examples
- java.util.Currency methods with example
- Java.util.Collections.disjoint() Method in java with Examples
- Java.util.Collections.rotate() Method in Java with Examples
- Java.lang.Short toString() method in Java with Examples
- Java lang.Long.reverse() method in Java with Examples
- Java lang.Long.numberOfTrailingZeros() method in Java with Examples
- Java lang.Long.numberOfLeadingZeros() method in Java with Examples
- Java lang.Long.byteValue() method in Java with Examples
- Java lang.Long.lowestOneBit() method in Java with Examples
- Java lang.Long.builtcount() method in Java with Examples
- Java lang.Long.highestOneBit() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



