1.浮点类型的数字转成String字符串
var f = 123.32342342
var s:String = "\(f)" //123.32342342
保留两位小数
var f = 123.32342342
var s = String(format: "%.2f", f) //123.32
转成十六进制格式字符串
let i = 255
let s:String = String(format: "%x", i) //ff
不足六位前面补0
let i = 255
let s:String = String(format: "%06x", i) //0000ff
网友评论