java.util.Currency getDefaultFractionDigits()

Description

The getDefaultFractionDigits() method of Currency class is use to get the how many digits is an allowable to specified Currency. Like for Instance for Philippine Peso has allowable decimal digits of 2 while the Japanese Yen is 0. This means that the Japanese Yen is having whole numbers on their calculation of their Currency.

Method Syntax

public int getDefaultFractionDigits()

Method Returns

The getDefaultFractionDigits() method of Currency class returns the default number of fraction digits used with this currency.

Compatibility

Java 1.4

Java Currency getDefaultFractionDigits() Example

Below is a simple java example on the usage of getDefaultFractionDigits() method of Currency class.

package com.javatutorialhq.java.examples;


import static java.lang.System.*;

import java.util.Currency;


/*
 * This example source code demonstrates the use of 
 * getDefaultFractionDigits() method of Currency class.
 */

public class CurrencyGetCurrencyCodeExample {

	public static void main(String[] args) {	
		
		// create an instance of Currency class
		Currency currency = Currency.getInstance("NZD");
		// prints the default currency fraction digit of New Zealand Dollar
		out.println("Result="+currency.getDefaultFractionDigits());		
	}
}

Basically on the above example, we just created a new Currency object with the Currency Code of NZD as method argument on the getInstance(). The NZD is the currency code of new zealand thus by invoking the method getDefaultFractionDigits() will give the default number of fraction digits for New Zealand Currency.

Sample Output

Below is the sample output when you run the above example.

Currency getDefaultFractionDigits() Sample Output