Common Swift collection casting or type conversion

Collection of Common Swift Casting  or Type Conversion

String to Double
var a  = "1.5"
var b  = (a as NSString).doubleValue

Double to String
var a : Double = 1.5
var b  = String(format:"%f", a)

Double to Int
var a : Double = 1.5
var b  = Double(a)

String to Float
var a  = "1.5"
var b  = (a as NSString).floatValue

String to Float
var a  = "1.5"
var b  = (a as NSString).intValue


0 nhận xét:

Đăng nhận xét