In this tutorial, you shall learn how to convert an integer value to a string value in Kotlin, using Int.toString() function, with example programs.
Kotlin – Convert integer to string
To convert an integer number to string in Kotlin, we can use Int.toString() method.
Steps to convert an integer to a string
- Consider that we are given an integer value
n
. - Call the toString() method on the integer
n
, and the function returns a string value created from this integer.
</>
Copy
n.toString()
Example
In the following program, we read a number n
from user and reverse it using the above steps.
Main.kt
</>
Copy
fun main() {
print("Enter an integer : ")
val n = readLine()!!.toInt()
val str = n.toString()
println("String value : $str")
}
Output #1
Enter an integer : 52413
String value : 52413
Related tutorials for the above program
Conclusion
In this Kotlin Tutorial, we learned how to convert a given integer to a string using Int.toString() method.