Wednesday, 7 March 2018

string formatting - How do I add left-padded zeros to a number in Java?




I have an integer 100, how do I format it to look like 00000100 (always 8 digits long)?


Answer



Try this:



String formattedNumber = String.format("%08d", number);

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...