Swift数据类型String、Int、Float、Double转换

String转数字

var text: String = "111"
var number: Int? = Int(text)
let text: String = "111"
var n: Int = (text as NSString).integerValue

数字转String

let number: Float = 123.5
var string: String = "\(number)"
var number: Float = 123.5
var string = String(number)

 数字之间互转

var doubleNumber = 1.8
var intNumber = 0
intNumber = Int(doubleNumber)

你可能感兴趣的:(iOS,swift,ios)