Skip to content

Commit

Permalink
Merge pull request ElemeFE#1469 from Leopoldthecoder/slider-precision
Browse files Browse the repository at this point in the history
Slider: fix a decimal display bug
  • Loading branch information
baiyaaaaa authored Dec 2, 2016
2 parents e0a5f1b + 9c301cd commit 395a129
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions packages/slider/src/main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
data() {
return {
precision: null,
precision: 0,
inputValue: null,
timeout: null,
hovering: false,
Expand Down Expand Up @@ -145,9 +145,7 @@
const lengthPerStep = 100 / ((this.max - this.min) / this.step);
const steps = Math.round(newPos / lengthPerStep);
let value = steps * lengthPerStep * (this.max - this.min) * 0.01 + this.min;
if (this.precision) {
value = parseFloat(value.toFixed(this.precision));
}
value = parseFloat(value.toFixed(this.precision));
this.$emit('input', value);
this.currentPosition = (this.value - this.min) / (this.max - this.min) * 100 + '%';
if (!this.dragging) {
Expand Down Expand Up @@ -232,9 +230,11 @@
} else if (this.value > this.max) {
this.$emit('input', this.max);
}
if (this.step && this.step < 1) {
this.precision = this.step.toPrecision(1).split('.')[1].length;
}
let precisions = [this.min, this.max, this.step].map(item => {
let decimal = ('' + item).split('.')[1];
return decimal ? decimal.length : 0;
});
this.precision = Math.max.apply(null, precisions);
this.inputValue = this.inputValue || this.value;
}
};
Expand Down

0 comments on commit 395a129

Please sign in to comment.