Fixed #967 - Decimal value for Slider step does not work

pull/1196/head^2
Tuğçe Küçükoğlu 2021-05-12 17:21:11 +03:00
parent 64df59f515
commit 5efaf616e1
1 changed files with 22 additions and 3 deletions

View File

@ -85,6 +85,25 @@ export default {
}
this.updateModel(event, newValue);
},
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor
decimalAdjust(type, value, exp) {
// If the exp is undefined or zero...
if (typeof exp === 'undefined' || +exp === 0) {
return Math[type](value);
}
value = +value;
exp = +exp;
// If the value is not a number or the exp is not an integer...
if (isNaN(value) || !(typeof exp === 'number' && exp % 1 === 0)) {
return NaN;
}
// Shift
value = value.toString().split('e');
value = Math[type](+(value[0] + 'e' + (value[1] ? (+value[1] - exp) : -exp)));
// Shift back
value = value.toString().split('e');
return +(value[0] + 'e' + (value[1] ? (+value[1] + exp) : exp));
},
updateModel(event, value) {
let newValue = value;
let modelValue;
@ -100,7 +119,7 @@ export default {
else if (newValue >= maxValue)
newValue = maxValue;
modelValue[0] = Math.floor(newValue);
modelValue[0] = this.decimalAdjust('floor', newValue, -2);
modelValue[1] = modelValue[1] || this.max;
}
else {
@ -111,7 +130,7 @@ export default {
newValue = minValue;
modelValue[0] = modelValue[0] || this.min;
modelValue[1] = Math.floor(newValue);
modelValue[1] = this.decimalAdjust('floor', newValue, -2);
}
}
else {
@ -120,7 +139,7 @@ export default {
else if (newValue > this.max)
newValue = this.max;
modelValue = Math.floor(newValue);
modelValue = this.decimalAdjust('floor', newValue, -2);
}
this.$emit('update:modelValue', modelValue);