fix: slider accuracy problems 1.x (#3386)

* fix: slider accuracy problems

* refactor: order of operations
pull/3414/head
John60676 2020-12-17 16:28:30 +08:00 committed by GitHub
parent ec064fe8c2
commit 6175fdbb0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

View File

@ -21,7 +21,8 @@ export function isNotTouchEvent(e) {
export function getClosestPoint(val, { marks, step, min, max }) {
const points = Object.keys(marks).map(parseFloat);
if (step !== null) {
const maxSteps = Math.floor((max - min) / step);
const base = 10 ** getPrecision(step);
const maxSteps = Math.floor((max * base - min * base) / (step * base));
const steps = Math.min((val - min) / step, maxSteps);
const closestStep = Math.round(steps) * step + min;
points.push(closestStep);