I have this to get a sum in a calculated field on a form
var a=this.getField("Text263");
var b=this.getField("Text256");
event.value=(a.value)/(b.value);
The problem is that I need it to return only a two digit number. If I change the format to Number I get a error message from some of the other field in the form because of the "this.getField" statement. I don't really want to go through the form cell and reformat so I am hope to add a small statement to the calculated field to get me a two digit return instead of "1234.83645871465198465" it should be "1234.84".
Your script does not take into consideration that the divisor might be zero or null. When I clear a sample form using your script with a format of 'None' for the field with your computation, I receive the string 'NaN' as a result. If I use 1 as a dividend and nothing for the divisor, I get the string 'Infinity'. And if I use -1 as a dividend, I get the string '-Infinity'.
You can use the 'util.printf()' method to round the results of your computation to 2 decimal places. If you want to limit your answer to 2 digits only, you will need to use the 'substr(-2)' method.
George Kaiser