Kotlin is a new programming language that was developed by Jetbrains. It is open-source and runs on the Java Virtual Machine (JVM). Kotlin can be used to create Android Apps, web apps, or any other type of application. One of the best things about Kotlin is how it reduces boilerplate code and makes coding much more concise.
The Kotlin programming language has several built-in data type for number that is very useful for performing calculations. In this blog post, we’ll cover the basics of working with numbers in Kotlin.
Following are 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