Java Data Type How to - Set minimum field-width specifier to the %f conversion








Question

We would like to know how to set minimum field-width specifier to the %f conversion.

Answer

import java.util.Formatter;
//  w  w w  .j a  v a  2  s.c o m
public class Main {
  public static void main(String args[]) {
    Formatter fmt = new Formatter();

    fmt.format("|%f|%n|%12f|%n|%012f|", 10.12345, 10.12345, 10.12345);

    System.out.println(fmt);

  }
}

The code above generates the following result.