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

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

In Kotlin, you can use format() function.val minutes = 5val strMinutes = "%02d".format(minutes)where, 2 is the total number of digits you want to display(including zero).Output: 05

View Article


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

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: 05This uses formatted method...

View Article


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

Use this simple Kotlin Extension functionfun Int.padWithZeros(): String { return this.toString().padStart(4, '0')}

View Article
Browsing all 23 articles
Browse latest View live