DecimalFormat SetMaximumFractionDigits() Example
Sets the maximum number of digits allowed in the fraction
DecimalFormatclass 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:-13-Jun-2008
*/
import java.text.*;
public class SetMaximumFractionDigits {
public static void main(String[] args) {
// Creates a DecimalFormat object
DecimalFormat d = new DecimalFormat();
//Gets the maximum number of digits allowed in the fraction portion of a number.
System.out.println("The digits allowed in the fraction portion of a number is: "
+ d.getMaximumFractionDigits());
//Sets the maximum number of digits allowed in the fraction
d.setMaximumFractionDigits(6);
System.out.println("The digits allowed in the fraction portion of a number is: "
+ d.getMaximumFractionDigits());
}
} |
Output of the Program
The digits allowed in the fraction portion of a number is: 3
The digits allowed in the fraction portion of a number is: 6 |
|