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 johncurrier for How can I pad an integer with zeros on the left?

$
0
0
public static String zeroPad(long number, int width) {
   long wrapAt = (long)Math.pow(10, width);
   return String.valueOf(number % wrapAt + wrapAt).substring(1);
}

The only problem with this approach is that it makes you put on your thinking hat to figure out how it works.


Viewing all articles
Browse latest Browse all 23

Trending Articles



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