Convert int to string in Kotlin
To convert a given int value to a string type value in Kotlin, you can use Int.toString()
function.
Call toString()
function on the given integer value, say intValue
.
intValue.toString()
The function returns a string value created from the content in the given integer value.
Examples
Convert the integer 2020 to a string value
In the following program, we take an integer value in intValue
variable. We convert this integer value to a string value and print it to output.
Kotlin Program
fun main() {
val intValue = 2020
val str = intValue.toString()
println(str)
}
Output
2020