I used below code for conversion from NSnumber to currency with locale.
let price = 12.34 as NSNumber
let formatter = NumberFormatter()
formatter.numberStyle = .currency
formatter.currencyCode = "USD"
formatter.locale = NSLocale(localeIdentifier: "zh_CN") as Locale
print(formatter.string(from: price)!)
Expected Output: $12.34 , Actual Output: US$12.34
Could you please help me to resolve this behaviour.
If you want a currency symbol other than the default for the currency code and Locale, you can manually specify that using the
currencySymbolproperty ofNumberFormatter.Other improvements to your code: don't use
NSLocalein Swift, useLocaleinstead, especially when you cast theNSLocaletoLocaleimmediately. You don't need to convert numbers toNSNumberjust to format them either, you simply need to callNumberFormatter.string(for:)instead ofstring(from:)when using numeric types other thanNSNumber.