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

Calculate percentage of dollar amount

jmason
Registered: Jun 22 2007
Posts: 73
Answered

Hello,
I am working in Acrobat 8 Pro, and I've got a form with two columns, that has the following calculations going on:

Field 1 - "TOTAL" Number field adding the sum of the previous $ fields in the first column.
Field 2 - "TOTAL" Number field adding the sum of the previous $ fields in the second column.
Field 3 - "DIFFERENCE" Number field that subtracts the second TOTAL field from the first TOTAL field.
Field 4 - I want to calculate the percentage of the DIFFERENCE field from the first TOTAL field.

(My test figures are $100 in Field 1 and $75 in Field 2, giving me $25 in field 3. Field 4 should display 25%.)

The first 3 fields are formatted as "Number" fields and work fine. The fourth field I have the following Simplified Field Notation: GFE15 / GFE14, and I've tried setting the Format to "None", "Number", and "Percentage". When I set it to "None", the percentage shows as .25% (a quarter of a percent). When I set it to "Number" or "Percentage", the field displays the correct figure (25%), but I get an error message that says: "The value entered does not match the format of the field [HUD1A15]".

I played with the "Set Field Calculation Order" option, but this did not help.

Any help is greatly appreciated!

My Product Information:
Acrobat Pro 8.1.3, Windows
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
I would format the Field 4 as 'Percentage' and write a custom calculation script.

When you make Field 4 as a "None" format and clear the form, what value displays in Field 4?

My form displays "NaN", (Not a Number)!

You could possibly receive 'Infinity' or 'Negative Infinity'.

What is the result of your division when your divisor is Zero?

A solution is:
event.value = ''; // assume null value for quotientvar fDivisor = this.getField('Field1').value; // divisor valuevar fDividend = this.getField('Field3').value; // dividend value// check for non-zero divisorif (fDivisor != 0) {// calculate for non-zero divisors onlyevent.value = fDividend / fDivisor; // compute quotient}

George Kaiser

jmason
Registered: Jun 22 2007
Posts: 73
gkaiseril,
THANK YOU!!!! I don't know JavaScript very well (I can only do VERY simple ones that I have a cheat sheet for), but the combination of formatting the field to 'Percentage' and your nifty custom code worked like a charm! You made my day, thanks again! =)