Scriptui-滑块百分比中的整数编号

发布于 2025-01-24 19:04:40 字数 875 浏览 4 评论 0原文

我有一个脚本,显示一个带有滑块栏的对话框窗口,旁边是静态文本。

文本显示了滑块栏的百分比(0到100)。

问题是该百分比以小数为单位显示,而我需要它以在整数中显示它们,因为代码的下一部分从文本中获取数字,而我不需要小数。

代码是:

    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()

有人知道该怎么做?

我已经在label.text和slide.value上尝试了Math.Round(),但是我不知道我是否无法正确使用它,或者它不是适合这种情况的正确代码。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我做我的改变 2025-01-31 19:04:40

我敢肯定,这样的行是在这种情况下获得回合数字的绝对正确方法:

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

如果在某个地方,您需要一个字符串,您可以通过var mystring = label.text.tostring获得字符串( );甚至var mystring ='' + label.text;。但是通常JavaScript/ExtendScript不在乎该值是数字或字符串。它与他们无关紧要。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文