Java DecimalFormat .setMaximumFractionDigits (int newValue)

Syntax

DecimalFormat.setMaximumFractionDigits(int newValue) has the following syntax.

public void setMaximumFractionDigits(int newValue)

Example

In the following code shows how to use DecimalFormat.setMaximumFractionDigits(int newValue) method.


//from  w w w . j  a v a2 s . c o  m
import java.text.DecimalFormat;

public class Main {
  public static void main(String[] argv) throws Exception {
    DecimalFormat format = new DecimalFormat();
    
    format.setMaximumFractionDigits(4);
    
    System.out.println(format.format(123456789.12345678));

  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.text »




DateFormat
DecimalFormat
NumberFormat
SimpleDateFormat