[IOSS]Swift数据类型转换

来源:互联网 发布:超级淘宝系统小说 编辑:程序博客网 时间:2024/06/08 07:21

[IOSS]Swift数据类型转换


        /*        整型 -> 浮点        */        let intLet : Int = 5        let doubleLet : Double = Double(intLet)        let floatLet : Float = Float(intLet)        print(intLet , doubleLet , floatLet)                /*        字符串 -> 整型        */        //swift1.x的语法        //let intString: String = "256"        //let transformInt: Int? = intString.toInt()        //swift2.x的语法        let intString: String = "123456"        let transformInt: Int? = Int(intString)        print(transformInt!)        print(transformInt) //不加" !"时打印后后有默认值 Optional(123456)        /*        整型 -> 字符串        */        let intFive : Int = 5        let strFive : String = String(intFive)        print(strFive)                /*        浮点 -> 字符串        */        let double : Double = 20.12        let stringDouble = NSString(format: "%f", double)        let stringDouble_ : String = String( double )        print(stringDouble,stringDouble_)        /*        字符串 -> 浮点        */        let strDouble : String = "20.12"        let doubleStr : Double = (strDouble as NSString).doubleValue        let doubleStr_ : Double = NSString(string: strDouble).doubleValue        print(doubleStr,doubleStr_)


0 0
原创粉丝点击