I have a Double, and i need show in label numbers in currency format, pt-BR format.
private var myValue: Double = 0.0
myLabel.text = "\(self.myValue)"
** i need convert this Double to pt-BR real **
i try this:
let convert = self.myValue as NSNumber
myLabel.text = "\(convert)"
CodePudding user response:
You should use NumberFormatter for this task. Here is an example:
Playground view:
let currency = 10.50
let formatter: NumberFormatter = {
let result = NumberFormatter()
result.locale = Locale(identifier: "pt-BR")
result.numberStyle = .currency
return result
}()
let label = UILabel()
label.text = formatter.string(for: currency)