fix(Stepper): can't work when step is small (#4675)

This commit is contained in:
neverland 2019-10-10 17:15:43 +08:00 committed by GitHub
parent cc03640576
commit e4bdd50d4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);