How to format decimal value in precision?

For example, %10.4f displays a number at least ten characters wide with four decimal places.

// Demonstrate the precision modifier.
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 output:
123.1234