Format to 2 decimal places in a 16-character field in Java

Description

The following code shows how to format to 2 decimal places in a 16-character field.

Example


//w  w w .  ja v a 2  s.  c  om
import java.util.Formatter;

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

    fmt = new Formatter();
    fmt.format("%16.2e", 123.1234567);
    System.out.println(fmt);

  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Data Format »




Java Formatter
Java Number Formatter