0
I have a function that I want to format the values to decimals with the Brazilian standard. Today my function is like this ...
func formatNumberToDecimal(value:Double) -> String {
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = NumberFormatter.Style.decimal
numberFormatter.groupingSeparator = "."
return numberFormatter.string(from: NSNumber(value:defaultValue)) ?? "Valor indefinido"
}
But it returns with a value in the format EN for example:
formatNumberToDecimal(1000.00)
// retorna o valor -> 1.000,00
I wonder how I can turn to en with two houses after the comma. In the example above it should return 1,000.00
Formatter has a method called
string(for: Any)
that Voce can pass a Double straight to it. No need to create an Nsnumber objectnumberFormatter.string(for: value) ?? "Valor indefinido"
– Leo Dabus