Quantcast
Viewing latest article 17
Browse Latest Browse All 23

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

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 latest article 17
Browse Latest Browse All 23

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>