Swift中浮点数Formatted

2023-06-18  本文已影响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
上一篇 下一篇

猜你喜欢

热点阅读