我想把-33.861382,151.210316,226.76转换为字符串。我试图键入cast它,但是unscucessful。
如何将float值转换为String?
如何将float值转换为String?
如果你想要更多的控制如何转换你可以使用stringWithFormat在NSString或NSNumberFormatter
原文链接:https://www.f2er.com/swift/320762.htmllet f = -33.861382 let s = NSString(format: "%.2f",f) let nf = NSNumberFormatter() nf.numberStyle = .DecimalStyle // Configure the number formatter to your liking let s2 = nf.stringFromNumber(f)