From ff0145a1299844334cc303ce61e9371011642e03 Mon Sep 17 00:00:00 2001 From: Rob Garrison Date: Mon, 17 Sep 2018 22:49:44 -0500 Subject: [PATCH] Fix clamp to step floor --- manage/config-dialog.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/manage/config-dialog.js b/manage/config-dialog.js index d749fada..4bfe4669 100644 --- a/manage/config-dialog.js +++ b/manage/config-dialog.js @@ -325,9 +325,15 @@ function configDialog(style) { if (value > max) { return max; } - const inv = 1 / (va.step || 1); // Don't restrict to integer values if step is undefined. - return typeof va.step !== 'undefined' ? Math.floor(inv * value) / inv : value; + if (typeof va.step === 'undefined') { + return value; + } + const step = va.step || 1; + const precision = (step.toString().split('.')[1] || 0).length + 1; + const inv = 1 / step; + // ECMA-262 only requires a precision of up to 21 significant digits + return Number((Math.floor(inv * value) / inv).toPrecision(precision > 21 ? 21 : precision)); } function updateVarOnInput(event, debounced = false) {