본문 바로가기
Study/Java

Java Currency getDefaultFractionDigits() Method

by 오늘만 사는 여자 2024. 8. 11.
728x90
반응형

Description

The Java 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()

Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

 

Parameters

NA

 

Return Value

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

Exception

NA

Getting Default Fraction Digits of EUR Currency Instance Example

The following example shows the usage of Java Currency getDefaultFractionDigits() method for EUR currency. We've first created a currency object using EUR as currency code and then its default fraction digits are printed.

 
Open Compiler
package com.tutorialspoint; import java.util.Currency; public class CurrencyDemo { public static void main(String args[]) { // create a currency with EUR code Currency curr = Currency.getInstance("EUR"); System.out.println("Default fraction digits for EUR = " + curr.getDefaultFractionDigits()); } }
 
 

Output

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

Default fraction digits for EUR = 2

Getting Default Fraction Digits of USD Currency Instance Example

The following example shows the usage of Java Currency getDefaultFractionDigits() method for USD currency. We've first created a currency object using USD as currency code and then its default fraction digits are printed.

 
Open Compiler
package com.tutorialspoint; import java.util.Currency; public class CurrencyDemo { public static void main(String args[]) { // create a currency with USD code Currency curr = Currency.getInstance("USD"); System.out.println("Default fraction digits for USD = " + curr.getDefaultFractionDigits()); } }
 
 

Output

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

Default fraction digits for USD = 2

Getting Default Fraction Digits of JPY Currency Instance Example

The following example shows the usage of Java Currency getDefaultFractionDigits() method for JPY currency. We've first created a currency object using JPY as currency code and then its default fraction digits are printed.

 
Open Compiler
package com.tutorialspoint; import java.util.Currency; public class CurrencyDemo { public static void main(String args[]) { // create a currency with JPY code Currency curr = Currency.getInstance("JPY"); System.out.println("Default fraction digits for JPY = " + curr.getDefaultFractionDigits()); } }
 

Output

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

Default fraction digits for JPY = 0

 

출처 : https://bullie.tistory.com/7

728x90
반응형

댓글