Scriptui-滑块百分比中的整数编号
我有一个脚本,显示一个带有滑块栏的对话框窗口,旁边是静态文本。
文本显示了滑块栏的百分比(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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我敢肯定,这样的行是在这种情况下获得回合数字的绝对正确方法:
如果在某个地方,您需要一个字符串,您可以通过
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:
If somewhere down-river you will need a string you can get the string via
var myString = Label.text.toString();
or evenvar myString = '' + Label.text;
. But usually JavaScript/Extendscript doesn't care either the value is a number or a string. It deals with them indiscriminately.