swift中需要将一个浮点数double格式化为2位小数点的字符串
swift double format string 2 point
iphone – Round double value to 2 decimal places – Stack Overflow
How to use println in Swift to format number – Stack Overflow
casting – Swift double to string – Stack Overflow
ios – Rounding a double value to x number of decimal places in swift – Stack Overflow
最后用:
let sizeKBDouble:Double = Double(sizeInBytes) / Double(sizeKB) let sizeKBDoubleStr = String(format: "%.2f", sizeKBDouble) sizeStr = sizeKBDoubleStr + " KB" |
即可。
转载请注明:在路上 » [已解决]swift 格式化浮点数为2位小数点的字符串