Data Type Java Tutorial

A precision specifier can be applied to the %f, %e, %g, and %s format specifiers.
When applying to floating-point data using the %f, %e, or %g specifiers,
it determines the number of decimal places displayed.
The default precision is 6.
For example, %10.4f displays a number at least ten characters wide with four
decimal places.

import java.util.Formatter;
public class MainClass {
  public static void main(String args[]) {
    Formatter fmt;
    fmt = new Formatter();
    fmt.format("%1.4f", 1234567890.123456789);
    System.out.println(fmt);
  }
}
1234567890.1235