diff --git a/packages/components/input-number/__tests__/input-number.test.tsx b/packages/components/input-number/__tests__/input-number.test.tsx index 537e31b885..1c6f3423db 100644 --- a/packages/components/input-number/__tests__/input-number.test.tsx +++ b/packages/components/input-number/__tests__/input-number.test.tsx @@ -94,6 +94,22 @@ describe('InputNumber.vue', () => { expect(wrapper.find('input').element.value).toEqual('4') }) + test('value decimals miss prop precision', async () => { + const num = ref(0.2) + const wrapper = mount(() => ( + + )) + const elInputNumber = wrapper.findComponent({ name: 'ElInputNumber' }).vm + elInputNumber.increase() + await nextTick() + expect(wrapper.find('input').element.value).toEqual('0.3') + num.value = 0.4 + await nextTick() + elInputNumber.decrease() + await nextTick() + expect(wrapper.find('input').element.value).toEqual('0.3') + }) + describe('precision accuracy 2', () => { const num = ref(0) const wrapper = mount(() => ( diff --git a/packages/components/input-number/src/input-number.vue b/packages/components/input-number/src/input-number.vue index 89607b5a4b..57165ac658 100644 --- a/packages/components/input-number/src/input-number.vue +++ b/packages/components/input-number/src/input-number.vue @@ -201,7 +201,7 @@ const verifyValue = ( newVal = isString(valueOnClear) ? { min, max }[valueOnClear] : valueOnClear } if (stepStrictly) { - newVal = Math.round(newVal / step) * step + newVal = toPrecision(Math.round(newVal / step) * step, precision) } if (!isUndefined(precision)) { newVal = toPrecision(newVal, precision)