swiftui formatter textfield double 2 decimal places code example
Example: swiftui formatter textfield double 2 decimal places
@State private var score = 0
let formatter: NumberFormatter = {
let formatter = NumberFormatter()
formatter.numberStyle = .decimal
formatter.minimumFractionDigits = 2
formatter.maximumFractionDigits = 2
return formatter
}()
//In body
TextField("MyScore", value: $score, formatter: formatter)