These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Calculated field

Spirit
Registered: May 16 2009
Posts: 10

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".

My Product Information:
Acrobat Pro 8.1.2, Windows
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
More than likely the error that is occurring is that the computed value is not always a number and you are trying to use that non-numeric value as a number in another field.

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