From 3edc7a9c2daa68e867c6ae96a7a40a0321f7e731 Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 10 Sep 2023 14:35:21 +1000 Subject: [PATCH] bugfix in rounding --- web/scripts/widgets.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/web/scripts/widgets.js b/web/scripts/widgets.js index 30caa6a8c..31fa40529 100644 --- a/web/scripts/widgets.js +++ b/web/scripts/widgets.js @@ -2,7 +2,7 @@ import { api } from "./api.js" function getNumberDefaults(inputData, defaultStep) { let defaultVal = inputData[1]["default"]; - let { min, max, step } = inputData[1]; + let { min, max, step, rounding, precision } = inputData[1]; if (defaultVal == undefined) defaultVal = 0; if (min == undefined) min = 0; @@ -10,11 +10,11 @@ function getNumberDefaults(inputData, defaultStep) { if (step == undefined) step = defaultStep; // precision is the number of decimal places to show. // by default, display the the smallest number of decimal places such that changes of size step are visible. - let precision = Math.max(-Math.floor(Math.log10(step)),0) + if (precision == undefined) precision = Math.max(-Math.floor(Math.log10(step)),0) // by default, round the value to those decimal places shown. - let round = Math.round(1000000*Math.pow(0.1,precision))/1000000; + if (rounding == undefined) rounding = Math.round(1000000*Math.pow(0.1,precision))/1000000; - return { val: defaultVal, config: { min, max, step: 10.0 * step, round, precision } }; + return { val: defaultVal, config: { min, max, step: 10.0 * step, rounding, precision } }; } export function addValueControlWidget(node, targetWidget, defaultValue = "randomize", values) {