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

How to Calculate a percentage of a salary increase or decrease?

emilyl1017
Registered: Jan 24 2011
Posts: 1

I am working on a form that is for position or rate change. The calculation i am trying to determine is the percent of a raise incraese or decrease.
I managed to get the calculations correct by using a simpliefied field notation. My original calucation was : (ValueA(New Pay)-ValueB(old Salary))/ValueB, which was put in resultC. The calcucation was correct, but no matter what field I am in, I get the error "the value entered does not match the format of the field [ResultsC].
 
I format the Results field to None, and the error does not appear, but the percentage is not only 2 decimal points.
 
Any help would be apprecaited.

My Product Information:
Acrobat Standard, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Until you fill in the divisor for the calculation, you will be dividing by a null, zero, value. What is the result of division by zero?

You need to use an 'if' statement to prevent division by a zero or null value. And that will require a custom calculation script.

The with a field format of 'Percentage' the simplist script is:

var nDivisor = this.getField("oldSalary").valueAsString; // get value for divisor
var nNewValue = this.getField("NewPay").valueAsString; // get new salary
// test for not being equal zero and not being equal to a null string
if(nDivisor != "0" & nDivisor) {
// we have a valid divisor
var nDifference = nNewValue - nDivisor; // compute difference
// divide difference of new salary less old salary by the old salary
event.value = nDifference / nDivisor; // compute decimal change
} else {
// null or zero divisor do nothing
event.value = ""; // clear result display
} // end of computation


To have a blank display when there are no values for computation set the field format to "None" and use the following script:

var nDivisor = this.getField("oldSalary").valueAsString; // get value for divisor
var nNewValue = this.getField("NewPay").valueAsString; // get new salary
// test for not being equal zero and not being equal to a null string
if(nDivisor != "0" & nDivisor != "" & nNewValue !="") {
// we have a valid divisor
var nDifference = nNewValue - nDivisor; // compute difference
// divide difference of new salary less old salary by the old salary
event.value = nDifference / nDivisor; // compute decimal change
AFPercent_Format(2, 0, 0); // format result as a percentage
} else {
// null or zero divisor do nothing
event.value = ""; // clear result display
AFNumber_Format(2, 0, 0, 0, "", false); // format to allow null display
} // end of computation


George Kaiser