Xcode 8.0 (8A218a) GM
Target: iOS 10 (Swift 3)
Consider the following code:
let number = NSDecimalNumber(decimal: 22.4)
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = .currency
numberFormatter.locale = Locale.current
let result = numberFormatter.string(from: number)
print(result!)
The result is:
¤22.40
(I have no idea what ¤
means.)
But if I initialize the locale such as:
numberFormatter.locale = Locale(identifier: "en_US")
The result will be:
$22.40
... which is what I'd expect in the first place.
Notice that this works in a Playground tho:
The problem seems to happen only on devices/simulators via Xcode launching.
(I tested on two different macOS -- at my workplace and at home.)
Any ideas on what's going on?
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.
This was happening to me in the Simulator, turns out it was an error in my scheme setup. Checkout the following steps:
I think your device language set to be chinese that is why ¤ symbol shown as currency symbol
I have same problems and I solve it by below code. Hope it is useful