Kotlin Number Tutorials

Some common use cases with number.

Add leading zeros to a number

val result = String.format("%05d", 2) // "00002"
val result2 = "15".padStart(5, '0') // "00015"

Convert number to String with comma for thousands

val formattedNumber = String.format("%,d", 51623); //51,623
val formattedDouble = String.format("%,.2f", 61303.23d); //61,303.23

Leave a Comment

Your email address will not be published. Required fields are marked *

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close