↧
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 ArticleAnswer 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 ArticleAnswer 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