Slider textbox precission


I have some problem that seems to be very easy to solve, but I can’t find the answer anywhere, probably my searching skills are not good :slight_smile:

My slider textBox displays values like that fo example: 1.076553234. Can’t I round it any way? To show instead 1.08, or even 1.1, or just 1.

How to do that? Could any one help with that? In std library there is something like cout precision. But here I can’t find anything like that. For any help thanks in advance.


One way is overriding Slider::getValueToText() and vice versa.

There might be an easier way though…



Great thanks I will check getValueToText()
But also other question I have and can’t find the answer. Can I set Slider to be step slider? I found in API Classes something like ThreeValueVertical. But what If I want 10 values? For example I have range from 0 to 100 and I want to slider jump every 10.


If your slider is connected to a AudioProcessorParameter, e.g. using AudioProcessorValueTreeState::SliderAttachment, it will respect the step parameter of the parameter created with AudioProcessorValueTreeState::createAndAddParameter()… I think that would also solve the precision problem, since the numbers would be rounded to the legal values…


Thanks for your help I need to experiment. But actually I know AudioProcessorValueTreeState but as I can’t remember if there was any precision or step function setup


Ok step values you can achieve with AudioProcessorValueTreeState::createAndAddParameter()

and NormalisableRange can be set with step definition.


Use the Slider::setRange() method – lets you control max, min, and the interval that defines the granularity of the slider, so you could create this with code like

mySlider->setRange(0, 100, 10);


bgporter thanks, yes I’ve just found that. But still have no idea how to set textbox precision display


The display precision is controlled by the interval value passed to setRange() – check the source code (in the version I have installed here, it’s around line 117 in modules/juce_gui_basics/widgets/juce_Slider.cpp). It should automatically truncate at the correct precision.


Hah, great thanks for your support.
I already know that you can set: slider.setRange(0.0f, 100.0f, 10.0f)

But unfortunately it’s not what I am looking for. I would like the slider move and also slider.getValue() fluently, but I just want displayed value to be truncate at correct precision. Do you know what I mean?


Hey pajczur! I’m running into the same problem, have you figured out a way to achieve this?


Slider::setNumDecimalPlacesToDisplay() ?