ios - 我如何/在哪里使用 NSNumberFormatter?

标签 ios swift nsnumberformatter

我是编码新手,在查看了一些答案后仍然需要帮助。

在我的代码中:

func labelInformation(){
     numLabels.text = newLabel.text
} 

当前结果:

228500.23

期望的结果:

228,500.23

我如何/在哪里使用 NSNumberFormatter?

最佳答案

像这样尝试:

let inputValue = 228500.23

let numberFormatter = NSNumberFormatter()

numberFormatter.numberStyle = .CurrencyStyle
numberFormatter.currencySymbol = ""

let outputString = numberFormatter.stringFromNumber(inputValue) ?? "0.00"

print(outputString)   // 228,500.23

关于ios - 我如何/在哪里使用 NSNumberFormatter?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34362357/

相关文章:

swift 4 : Sorting data with Firestore

ios - .cgColor 颜色的 UIColor 扩展?

ios - SwiftUI 模态演示仅在 navigationBarItems 中有效

swift - 没有四舍五入的数字格式。 Xcode 中的一种行为在 playground 中转换出另一种行为

ios - 快速将 Double 转换为科学记数法

iOS:NSNumberFormatter 从本地货币到双倍

iphone - 从通讯簿调用联系人

ios - 有没有办法将用于 MKUserLocation 蓝点的 MKAnnotationView 子类化?

ios - react-native 中的模态底部菜单

ios - UILabel 未显示在自定义 UIView 屏幕中