ProAnswers.org

What is zero padding and How to pad with zeros rather than spaces?

0 padds output with zeros rather than spaces.

Syntax

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

Example

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

import java.util.Formatter;
public class Main {
public static void main(String args[]) {
Formatter fmt = new Formatter();
fmt.format("0%g
", 123.1);

}
}
The output:
0123.100