ScriptUI - Integer number in slider percentage

160 views Asked by At

I have a script that shows a dialog window with a slider bar, next to a static text.

The text shows the percentage of the slider bar (0 to 100).

The problem is that the percentage is shown in decimals, while I would need it to show them in integers, as the next part of the code takes the number from the text and I don't need decimals.

The code is :

    var Dial = new Window ("dialog");
    Dial.alignChildren = ["right","center"];
    var Group1 = Dial.add ("group");
    var Slide = Group1.add ("slider");
    Slide.minvalue = 0;
    Slide.maxvalue = 100;
    Slide.value = 50;
    Slide.preferredSize.width = 300;
    Slide.onChanging = function () {
        Label.text = Slide.value;
        }
    var Label = Group1.add ("statictext");
    Label.preferredSize.width = 30;
    Label.text = Slide.value;
    var Button1 = Dial.add ("button");
    Button1.text = "OK";
    Button1.onClick = function () {
        Dial.close()
        }
    Dial.show()

Someone has any idea how to do it?

I've tried with Math.round() on Label.text and on Slide.value, but I don't know if I can't use it correctly or if it's not the right code for this case.

1

There are 1 answers

1
Yuri Khristich On BEST ANSWER

I'm sure the line like this is the absolute correct way to get the round numbers in this case:

Label.text = Math.round(Slide.value);

If somewhere down-river you will need a string you can get the string via var myString = Label.text.toString(); or even var myString = '' + Label.text;. But usually JavaScript/Extendscript doesn't care either the value is a number or a string. It deals with them indiscriminately.