From e4bdd50d4b4adbfadc02ffbbd96b20f336fc48f2 Mon Sep 17 00:00:00 2001 From: neverland Date: Thu, 10 Oct 2019 17:15:43 +0800 Subject: [PATCH] fix(Stepper): can't work when step is small (#4675) --- src/stepper/index.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/stepper/index.js b/src/stepper/index.js index 14db7b9d4..7ecd149fb 100644 --- a/src/stepper/index.js +++ b/src/stepper/index.js @@ -11,6 +11,12 @@ function equal(value1, value2) { return String(value1) === String(value2); } +// add num and avoid float number +function add(num1, num2) { + const cardinal = 10 ** 10; + return Math.round((num1 + num2) * cardinal) / cardinal; +} + export default createComponent({ props: { value: null, @@ -171,14 +177,7 @@ export default createComponent({ const diff = type === 'minus' ? -this.step : +this.step; - let value = +this.currentValue + diff; - - // avoid float number - if (!isDef(this.decimalLength)) { - value = Math.round(value * 100) / 100; - } - - value = this.format(value); + const value = this.format(add(+this.currentValue, diff)); this.emitChange(value); this.$emit(type);