To convert a float to a string in Kotlin, you can use the toString()
method of the Float class.
In this example,
float1
with a value of 3.14
.toString()
method to convert the float to a string and store the result in a variable str1
.str1
.// Convert Float 3.14 to String
fun main() {
val float1 = 3.14f
val str1 = float1.toString()
println("String value is: $str1")
}
String value is: 3.14
In this example,
float2
with a value of 10.5
.toString()
method to convert the float to a string and store the result in a variable str2
.str2
.// Convert Float 10.5 to String
fun main() {
val float2 = 10.5f
val str2 = float2.toString()
println("String value is: $str2")
}
String value is: 10.5
In this tutorial, we learned How to convert Float to String in Kotlin language with well detailed examples.