Java.util.Currency.getDefaultFractionDigits() Method


Advertisements


Description

The java.util.Currency.getDefaultFractionDigits() method gets the default number of this currency's fraction digits.

Declaration

Following is the declaration for java.util.Currency.getDefaultFractionDigits() method

public int getDefaultFractionDigits()

Parameters

  • NA

Return Value

This method returns the default number of fraction digits used with this currency

Exception

  • NA

Example

The following example shows the usage of java.util.Currency.getDefaultFractionDigits() method.

package com.tutorialspoint;

import java.util.*;

public public class CurrencyDemo {

   public static void main(String args[]) {

   // create 2 different currencies
   Currency curr1 = Currency.getInstance("USD");
   Currency curr2 = Currency.getInstance("JPY");

   // print their fraction digits
   int usdDigits = curr1.getDefaultFractionDigits();
   System.out.println("USD fraction digits:" + usdDigits);
   int jpyDigits = curr2.getDefaultFractionDigits();
   System.out.println("JPY fraction digits:" + jpyDigits);
   }
}

Let us compile and run the above program, this will produce the following result:

USD fraction digits:2
JPY fraction digits:0

java_util_currency.htm

Advertisements