类型不同进行四则运算,需要先转换类型否则会报错。
let a:CGFloat = 5.5
let b:Int = 10
let c:Int = 3
let d = Int(a) + b
let e = CGFloat(b) - a
let f = Int(a) * b
let g = b / c
let h = b % c
let i = a / CGFloat(c)
let j = a.truncatingRemainder(dividingBy:CGFloat(c)) //浮点型取余数
输出结果
AE086196-3CD6-4820-B9C3-B04ED2FD7879.png
网友评论