问题
I'm new to code and after reviewing a few answers still need a hand with this.
In my code:
func labelInformation(){
numLabels.text = newLabel.text
}
Current result:
228500.23
Desired result:
228,500.23
How/where do I use NSNumberFormatter?
回答1:
Try like this:
let inputValue = 228500.23
let numberFormatter = NSNumberFormatter()
numberFormatter.numberStyle = .CurrencyStyle
numberFormatter.currencySymbol = ""
let outputString = numberFormatter.stringFromNumber(inputValue) ?? "0.00"
print(outputString) // 228,500.23
来源:https://stackoverflow.com/questions/34360857/how-where-do-i-use-nsnumberformatter