Display Value Rounding
-
Hey Gang,
I've created custom labels to display knob values. When the knob stepSize is set to 1.0, all works well. But when stepSize is set to 0.1 or 0.01, the decimal displays an endless amount of numbers (2.984057975... for example). How do I stop/round the decimal at say tenths (0.01) instead of displaying the full amount?
Here is the simple code I used to display the values.
const var EQGainknb1 = Content.getComponent("EQGainknb1"); const var Label1 = Content.getComponent("Label1"); inline function onEQGainknb1Control(component, value) { Label1.set("text", EQGainknb1.getValue()); }; Content.getComponent("EQGainknb1").setControlCallback(onEQGainknb1Control);
-
@trillbilly Here you go
Math.round() will do the job :)Label1.set("text", Math.round(EQGainknb1.getValue()));
-
@trillbill You can use Engine.doubleToString() to limit the number of decimal places.
Engine.doubleToString(EQGainknb1.getValue(), 2);
-
@Dan-Korneff Do I implement this directly in the callback?
@Natan This works great except it rounds to the nearest whole number it seems. Can I make it round the nearest tenth?
-
Label1.set("text", Engine.doubleToString(EQGainknb1.getValue(), 2));
-
@Dan-Korneff Ya, my mistake, I tried this at first with no luck but made an error. This is it. Thanks!
-
@trillbilly Yeah, The One dan Supplied is the Answer,
Exactly, Just replace with one you posted above:const var EQGainknb1 = Content.getComponent("EQGainknb1"); const var Label1 = Content.getComponent("Label1"); inline function onEQGainknb1Control(component, value) { Label1.set("text",Engine.doubleToString(EQGainknb1.getValue(), 2)); // Play with this to add more digits }; Content.getComponent("EQGainknb1").setControlCallback(onEQGainknb1Control);
HiseSnippet 975.3ocsV0saaaCElxwbqVctXEnO.D4JafTW4z+FPvPciiSgwRR8lxB1tpiVj1lHTjBRTswsnOHauI8t7.zGl9FrcnjrkxpRWpAl7M97K+NGcNeTSh0A7jDcLxo0oKi3HmuC6uTYVLbAUnPiO.4bG7wzDCOljqZ+kQzjDNC43r0KrJbZ0Dk87omsOURUA7RUHzYZQ.+HQnvTpcxfeRHkGRY7SEgU79QCFGnUC0RcJfmsvdnHZv4z47SnV2ZfQNeyHlvni8MTCOA7YeMao+B8aT49elHQLUxsB8Q9PhxUiFtPHYSVUqIHjSyI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