diff --git a/src/InputNumber.tsx b/src/InputNumber.tsx index b8524c82..e23a74f2 100644 --- a/src/InputNumber.tsx +++ b/src/InputNumber.tsx @@ -285,7 +285,7 @@ const InputNumber = React.forwardRef( if (!readOnly && !disabled) { const numStr = updateValue.toString(); const mergedPrecision = getPrecision(numStr, userTyping); - if (mergedPrecision) { + if (mergedPrecision >= 0) { updateValue = getMiniDecimal(toFixed(numStr, '.', mergedPrecision)); } diff --git a/tests/decimal.test.tsx b/tests/decimal.test.tsx index 345a6123..651c7b29 100644 --- a/tests/decimal.test.tsx +++ b/tests/decimal.test.tsx @@ -115,6 +115,16 @@ describe('InputNumber.Decimal', () => { expect(wrapper.getInputValue()).toEqual('1.00'); }); + it('zero precision should work',()=>{ + const onChange = jest.fn(); + const wrapper = mount(); + + wrapper.changeValue('1.44'); + wrapper.blurInput(); + expect(onChange).toHaveBeenCalledWith(1); + expect(wrapper.getInputValue()).toEqual('1'); + }) + it('should not trigger onChange when blur InputNumber with precision', () => { const onChange = jest.fn(); const wrapper = mount();