Bug - Extendscript editnumber control autorounding
I've found a bug with the Extendscript editnumber control and a workaround. Please see my related post in the Photoshop forum, the bug is slightly different. Tested on macOS and Windows 10 Pro, Bridge 12.0.4 and Bridge 15.1.2.
When a decimal number is entered into an editnumber control (in an Extendscript window), the decimal is incorrectly rounded to two decimal places. If the script requires more precision, there is a workaround for Bridge 12. Please see the posted snippet.
This workaround does NOT function in Bridge 15, and editnumber.value is always zero.
To test, type in a number such as 0.00255. Without the workaround code, this is rounded to 0. With the workaround, the typed value is retained (Bridge 12.)
/*
This is a test snippet to demonstrate editnumber bugs in Bridge 12 and Bridge 15.
In both versions, editnumber entry is autorounded to two decimal places.
This can be worked around in Bridge 12.
In Bridge 15, editnumber.value == 0 and editnumber.text is autorounded so
the workaround fails.
*/
test();
function test(){
try{
var weight = '';
rnWindow = new Window ('palette', 'Editnumber test', undefined, {closeButton:true});
rnPanel = rnWindow.add('panel', [0, 0, 650, 540], '');
rnPanel.num1 = rnPanel.add('editnumber {justify:"left"}', undefined, 0);
rnPanel.num1.minimumSize = [90, 20];
rnPanel.button1 = rnPanel.add('button', undefined, 'Display');
if(BridgeTalk.appVersion < 15){
//workaround
rnPanel.num1.onChanging = function(){
weight = rnPanel.num1.value.toString();
}
rnPanel.num1.onDeactivate = function(){
rnPanel.num1.value = eval(weight);
rnPanel.num1.text = weight;
}
//end workaround
rnPanel.button1.onClick = function(){
Window.alert(weight + '\r' + rnPanel.num1.value.toString());
}
}
else{
rnPanel.num1.onChanging = function(){
weight = rnPanel.num1.text;
}
rnPanel.button1.onClick = function(){
Window.alert(weight + '\r' + rnPanel.num1.value.toString());
}
}
rnWindow.layout.layout(true);
rnWindow.show();
}
catch(e){
Window.alert(e + ' ' + e.line);
}
}
