Swift - 数字格式化转成字符串(保留两位小数)
1,下面是一个浮点类型的数字转成String字符串的例子
1
2
|
var f = 123.32342342 var s: String = "\(f)" //123.32342342 |
2,如果要保留两位小数
1
2
|
var f = 123.32342342 var s = String (format: "%.2f" , f) //123.32 |
1,下面是一个浮点类型的数字转成String字符串的例子
1
2
|
var f = 123.32342342 var s: String = "\(f)" //123.32342342 |
2,如果要保留两位小数
1
2
|
var f = 123.32342342 var s = String (format: "%.2f" , f) //123.32 |