Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/InputNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
10 changes: 10 additions & 0 deletions tests/decimal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<InputNumber onChange={onChange} precision={0} />);

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(<InputNumber precision={2} defaultValue={2} onChange={onChange} />);
Expand Down