Convert double to string in Swift

To convert a Double to a String in Swift, you can use the String(doubleValue) initializer. For example:

let myDouble = 3.14159
let myString = String(myDouble)

This will create a new String with the value “3.14159”.

Alternatively, you can use string interpolation to include the value of the Double in a string. This allows you to include the double value in a string that contains other text or characters. For example:

let myDouble = 3.14159
let myString = "The value of pi is: \(myDouble)"

This will create a new String with the value “The value of pi is: 3.14159”.

Spread the love

Leave a comment