Format 4 decimal places in Java

Description

The following code shows how to format 4 decimal places.

Example


/* ww  w .ja  va 2 s . co  m*/
import java.util.Formatter;

public class Main {
  public static void main(String args[]) {
    Formatter fmt = new Formatter();

    // Format 4 decimal places.
    fmt.format("%.4f", 123.1234567);
    System.out.println(fmt);

  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Data Format »




Java Formatter
Java Number Formatter