Format an Integer using Java String Format

String.format("%03d", 1)  // => "001"
//              │││   └── print the number one
//              ││└────── ... as a decimal integer
//              │└─────── ... minimum of 3 characters wide
//              └──────── ... pad with zeroes instead of spaces

See java.util.Formatter for more information.


Use %03d in the format specifier for the integer. The 0 means that the number will be zero-filled if it is less than three (in this case) digits.

See the Formatter docs for other modifiers.