Mega Code Archive

 
Categories / Java Tutorial / Development
 

Specifying a Minimum Field Width

An integer between the % sign and the format conversion code acts as a minimum field width specifier. The default padding is done with spaces. If you want to pad with 0's, place a 0 before the field width specifier. For example, %05d will pad a number of less than five digits with 0's. import java.util.Formatter; public class MainClass {   public static void main(String args[]) {     Formatter fmt = new Formatter();     fmt.format("%05d", 88);     System.out.println(fmt);   } } 00088