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

$
0
0

If you are on Java 15 and above,

var minutes = 5var strMinutes = "%02d".formatted(minutes)

where, 2 is the total number of digits you want to display(including zero).

Output: 05

This uses formatted method part of instance method on Strings called which does the same as the static String.format(str,x,y,z)


Viewing all articles
Browse latest Browse all 23

Latest Images

Trending Articles



Latest Images

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