美文网首页
Swift中浮点数Formatted

Swift中浮点数Formatted

作者: 过客又见过客 | 来源:发表于2023-06-18 11:04 被阅读0次
    import Foundation
    let readjustment = 1234.56789
    let a = readjustment.formatted(.number.precision(.fractionLength(2)))
    print(a) // 1,234.57
    let locale = Locale(identifier: "ff_Adlm_GN")
    let b = readjustment.formatted(.number.precision(.fractionLength(2)).locale(locale))
    print(b) // 𞥑⹁𞥒𞥓𞥔.𞥕𞥗
    
    let v = 1234.56789
    v.formatted(.currency(code: "ESP").presentation(.narrow)) // ₧1,235
    v.formatted(.currency(code: "USD").presentation(.narrow)) // $1,234.57
    v.formatted(.currency(code: "KWD").presentation(.narrow)) // KWD 1,234.568
    v.formatted(.currency(code: "UYW").presentation(.narrow)) // UYW 1,234.5679
    

    相关文章

      网友评论

          本文标题:Swift中浮点数Formatted

          本文链接:https://www.haomeiwen.com/subject/nzojydtx.html