Swift 3 and NumberFormatter (.currency) == ¤?

老子叫甜甜 提交于 2019-12-04 03:24:30
Nam Pham

I have same problems and I solve it by below code. Hope it is useful

func formatCurrency(value: Double) -> String {
    let formatter = NumberFormatter()
    formatter.numberStyle = .currency
    formatter.maximumFractionDigits = 2
    formatter.locale = Locale(identifier: Locale.current.identifier)
    let result = formatter.string(from: value as NSNumber)
    return result!
}

This was happening to me in the Simulator, turns out it was an error in my scheme setup. Checkout the following steps:

  1. Click on Set Active Scheme (click directly to the left of the simulator type i.e. iPhone 7 Plus etc.)
  2. Click Edit Scheme...
  3. Click into the Run settings on the left
  4. Set Application Region to desired region
  5. Set Application Language to desired language
  6. Try running your application again, you should no longer have it displaying the "¤" symbol and instead it should reflect the correct currency symbol.

Answering my own question: recreate the project. :\

The project was started off in Xcode 7 + Swift 2 and then "migrated" to Xcode 8 + Swift 3 (manually). Something must have gone wrong. I don't know what (and I don't want to know).

This wasn't a huge project, so I spent like 40 minutes moving files around. If that was a big project I would be f....d by now.

Xcode pls.

I think your device language set to be chinese that is why ¤ symbol shown as currency symbol

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!