Field-width specifier for float point numbers with Formatter in Java

Description

The following code shows how to field-width specifier for float point numbers with Formatter.

Example


/*from w ww  . j a va 2  s . c  o  m*/
import java.util.*; 
 
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.





















Home »
  Java Tutorial »
    Data Format »




Java Formatter
Java Number Formatter