Java Currency Class: getDefaultFractionDigits() Method
public int getDefaultFractionDigits()
The getDefaultFractionDigits() method is used to get the default number of fraction digits used with a given 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.
Package: java.util
Java Platform: Java SE 8
Syntax:
getDefaultFractionDigits()Return Value:
The default number of fraction digits used with this currency
Return Value Type: int
Example:Java Currency class: getDefaultFractionDigits() Method
import java.util.*;
public class Main {
public static void main(String args[]) {
// create 2 currencies (Japan Yen and United States Dollar)
Currency cur1 = Currency.getInstance("JPY");
Currency cur2 = Currency.getInstance("USD");
// Print their fraction digits
int dg1 = cur1.getDefaultFractionDigits();
System.out.println("JPY fraction digits: " + dg1);
int dg2 = cur2.getDefaultFractionDigits();
System.out.println("USD fraction digits: " + dg2);
}
}
Output:
JPY fraction digits: 0 USD fraction digits: 2
Java Code Editor:
Previous:getCurrencycode Method
Next:getDisplayname Method
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/java-tutorial/util/currency/java_currency_getdefaultfractiondigits.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics