Quantcast
Channel: How can I pad an integer with zeros on the left? - Stack Overflow
Viewing all articles
Browse latest Browse all 23

Answer by Pirate for How can I pad an integer with zeros on the left?

$
0
0

You can add leading 0 to your string like this. Define a string that will be the maximum length of the string that you want. In my case i need a string that will be only 9 char long.

String d = "602939";d = "000000000".substring(0, (9-d.length())) + d;System.out.println(d);

Output : 000602939


Viewing all articles
Browse latest Browse all 23

Latest Images

Trending Articles





Latest Images