Я пытаюсь реализовать калькулятор через формы Эврика.
В десятичной строке допускается ввод нескольких десятичных периодов.Я хочу ограничить его только одним десятичным периодом.Например, я могу ввести «3 .... 5».Но я хочу ввести только «3,5».
Вот мой код:
<<< DecimalRow() {
$0.tag = Tags.term
$0.title = "Term (Years)"
$0.baseCell.accessibilityLabel = $0.title
$0.formatter = DecimalFormatter()
$0.placeholder = "Years"
$0.add(rule: RuleRequired(msg: "Term field is required."))
$0.add(rule: RuleGreaterThan(min: 0, msg: "Term must be
greater than zero."))
$0.useFormatterDuringInput = true
$0.validationOptions = .validatesOnDemand
// DecimalFormatter
class DecimalPercentageFormatter: NumberFormatter {
init(minimumFractionDigits: Int = 2, maximumFractionDigits: Int = 2) {
super.init()
self.minimumFractionDigits = minimumFractionDigits
self.maximumFractionDigits = maximumFractionDigits
locale = Locale.current
numberStyle = .percent
positiveSuffix = "%"
negativeSuffix = "%"
}
}