最新消息:20210917 已从crifan.com换到crifan.org

[已解决]swift 格式化浮点数为2位小数点的字符串

Swift crifan 4969浏览 0评论

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位小数点的字符串

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
94 queries in 0.199 seconds, using 23.29MB memory