Convert String to Number (Integer, Float, Double)
Converting a string to a number is simple thanks to Swift. The following code will take the number 42 and convert it to an int, float and double.
let number = 42 let int = Int(number) let float = Float(number) let double = Double(number) print(int) print(float) print(double)
It will then print the results to the console which are:
42 42.0 42.0