0

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)"
arcobaleno
  • 40
  • 4
  • 1
    Does this answer your question? [How to format a Double into Currency - Swift 3](https://stackoverflow.com/questions/41558832/how-to-format-a-double-into-currency-swift-3) – koen Dec 21 '22 at 19:12

1 Answers1

0

You should use NumberFormatter for this task. Here is an example:

Playground view:

enter image description here

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)
koen
  • 5,383
  • 7
  • 50
  • 89