Sunday, August 7, 2011

Java: Left padding a number with zero


Share at Facebook

For padding any string with zeros at left side, you can easily use the String.format() of Java. Here is an example code.


int number = 10;
System.out.println(String.format("%05d",number));


Output will be00010




No comments: