I want to convert a Float into a string.
myFloat: Float = 99.0
myString: String
How would I convert myFloat
into a string so I can assign the following code
myString = myFloat
I want to convert a Float into a string.
myFloat: Float = 99.0
myString: String
How would I convert myFloat
into a string so I can assign the following code
myString = myFloat
Similar to Connor's answer, you can do the following to have a little more control about how your Double or Float is dislpayed...
let myStringToTwoDecimals = String(format:"%.2f", myFloat)
This is basically like stringWithFormat in objC.
You can use String Interpolation:
var myFloat: Float = 99.0
var myString: String = "\(myFloat)"