NumberFormatter: is currency incompatible with positivePrefix?

Viewed 155

I stumbled on an issue related to NumberFormatter. When I set the positivePrefix to the plusSign, the currency symbol is no longer there.

Is that a bug or did I miss something?

let formatter = NumberFormatter()
formatter.numberStyle = .currency
formatter.minimumFractionDigits = 0
formatter.currencyCode = "EUR"
formatter.maximumFractionDigits = 2
formatter.positivePrefix = formatter.plusSign // Remove that to get €25 (depends on your locale)
let price = 25.0
let s = formatter.string(from: NSNumber(value: price))

print("Price: \(s)"). // "Price: +25"
0 Answers
Related