Reputation: 14470
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
Upvotes: 0
Views: 7529
Reputation: 1567
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.
Upvotes: 8
Reputation: 64644
You can use String Interpolation:
var myFloat: Float = 99.0
var myString: String = "\(myFloat)"
Upvotes: 0