Java Format Zero Padding

Description

0 padds output with zeros rather than spaces.

Syntax

fmt.format("0%g\n", 123.1);

Example

The 0 flag causes output to be padded with zeros rather than spaces.


import java.util.Formatter;
// w  w w  . ja  va  2s  .c o m
public class Main {
  public static void main(String args[]) {
    Formatter fmt = new Formatter();
    fmt.format("0%g\n", 123.1);

  }
}

The output:





















Home »
  Java Tutorial »
    Data Format »




Java Formatter
Java Number Formatter