NumberFormat SetMaximumFractionDigits() Example
Sets the maximum number of digits allowed in the fraction portion of a number.
NumberFormatclass SetMaximumFractionDigits() method example. This example shows you how to use SetMaximumFractionDigits() method.This method Sets the maximum number of digits allowed in the fraction portion of a number.
Here is the code:-
/**
* @Program that Sets the maximum number of digits allowed in the fraction
* portion of a number.
* SetMaximumFractionDigits.java
* Author:-RoseIndia Team
* Date:-17-Jun-2008
*/
import java.text.*;
import java.util.*;
public class SetMaximumFractionDigits {
public static void main(String[] args) {
//Creating Numberformat instance
NumberFormat nf = NumberFormat.getIntegerInstance();
// Returns the maximum number of digits allowed in the fraction
System.out.println("Maximum number of digits allowed in the fraction is: "
+nf.getMaximumFractionDigits());
nf.setMaximumFractionDigits(2);
System.out.println("Maximum number of digits allowed in the fraction is: "
+nf.getMaximumFractionDigits());
}
} |
Output of the program:-
Maximum number of digits allowed in the fraction is: 0
Maximum number of digits allowed in the fraction is: 2 |
|