The number input box cannot enter decimals

PM: This number input box cannot enter decimals

Faced with this problem, there are two ways to solve it. You can solve this problem according to two methods. The specific one depends on the requirements.

round decimals

Add precision attribute to Input

          <InputNumber
            stringMode={true}
            min={1}
            max={65535}
            step={1}
            precision={0}
          />

Error message cannot fill in decimals

Error message using antd form item custom validation validator

         <Form.Item
          label="保留天数"
          name="day"
          rules={[
            { required: true, message: '请填写保留天数' },
            {
              type: 'number',
              min: 0,
              max: 365 * 100,
              message: '请填写 0~36500 之间的整数',
            },
						{
              validator: (_, value: number) => {
                if (value && value.toString().includes('.')) {
                  return Promise.reject('请填写一个正整数作为天数')
                }
                return Promise.resolve()
              },
            },
          ]}
        >
          <InputNumber placeholder="选填写保留天数" addonAfter="天" />
        </Form.Item>

Guess you like

Origin blog.csdn.net/qq_41536505/article/details/129315514