To convert a float to a string in Swift, you can use the String
initializer with the float value.
In this example,
float1
with a value of 3.14
.String
initializer to convert the float to a string and store the result in a variable str1
.str1
.let float1: Float = 3.14
let str1 = String(float1)
print("String value is:", str1)
String value is: 3.14
In this example,
float2
with a value of 10.5
.String
initializer to convert the float to a string and store the result in a variable str2
.str2
.let float2: Float = 10.5
let str2 = String(float2)
print("String value is:", str2)
String value is: 10.5
In this tutorial, we learned How to convert Float to String in Swift language with well detailed examples.