HomeiOS Developmentios - NumberFormatter unusual conduct in UITextField

ios – NumberFormatter unusual conduct in UITextField


i am attempting so as to add spacing to a quantity on enter, however after 1000 the formatter resets the worth

amountTextField.addTarget(self, motion: #selector(textFieldFilter(_:)), for: .editingChanged)
@objc non-public func textFieldFilter(_ textField: UITextField) {
        guard let textual content = textField.textual content else {return}
        print("String textual content(textual content)")
        print("Integer textual content(Int(textual content))")
        let formatter = NumberFormatter()
        formatter.groupingSeparator = " "
        formatter.usesGroupingSeparator = true
        formatter.groupingSize = 3
        formatter.numberStyle = .decimal
        textField.textual content = formatter.string(for: Int(textual content))
    }

In console prints this:

String textual content 1
Integer textual content Elective(1)
String textual content 10
Integer textual content Elective(10)
String textual content 100
Integer textual content Elective(100)
String textual content 1000
Integer textual content Elective(1000)
String textual content 1 0000
Integer textual content nil

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments