How/where do I use NSNumberFormatter?

后端 未结 1 724
感动是毒
感动是毒 2021-01-29 06:59

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
         


        
相关标签:
1条回答
  • 2021-01-29 07:06

    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
    
    0 讨论(0)
提交回复
热议问题