Java: how to add leading zeros to a number









String num = "123";
try {
num = String.format("%05d",
Integer.parseInt(num));
} catch (Throwable t) {
t.printStackTrace();
}
System.out.println(num);
// 00123




No comments:

Post a Comment