Skip to content

Commit e4bdd50

Browse files
authored
fix(Stepper): can't work when step is small (youzan#4675)
1 parent cc03640 commit e4bdd50

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

src/stepper/index.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ function equal(value1, value2) {
1111
return String(value1) === String(value2);
1212
}
1313

14+
// add num and avoid float number
15+
function add(num1, num2) {
16+
const cardinal = 10 ** 10;
17+
return Math.round((num1 + num2) * cardinal) / cardinal;
18+
}
19+
1420
export default createComponent({
1521
props: {
1622
value: null,
@@ -171,14 +177,7 @@ export default createComponent({
171177

172178
const diff = type === 'minus' ? -this.step : +this.step;
173179

174-
let value = +this.currentValue + diff;
175-
176-
// avoid float number
177-
if (!isDef(this.decimalLength)) {
178-
value = Math.round(value * 100) / 100;
179-
}
180-
181-
value = this.format(value);
180+
const value = this.format(add(+this.currentValue, diff));
182181

183182
this.emitChange(value);
184183
this.$emit(type);

0 commit comments

Comments
 (0)