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

Percentage calculations in forms

billh098
Registered: Jun 6 2009
Posts: 47
Answered

Hello,
I am having a problem in getting this formula right. I have 3 fields which I called X,Y and Z. X is the dollar amount that a user can change. ie $10,000. Next I then have a field called Y that is a percentage of that dollar amount. ie 10%. Then finally I have a field called Z that is the result of that dollar amount after the percentage has been subtracted. ie $1000.

In the Y field I have entered the code below in the "Custom Format Script" so that the number is the correct display of %. ie 10% not 1000.00%

if (event.value != "") {
event.value = event.value + "%"
}

Next I have a code below that is to be entered somewhere but not sure where.

var a = this.getField("Field X");
var b = this.getField("Field Y");
event.value = x.value * (y.value / 100)

This is far as I have made it. can you please help with this so that I can get the following:

Field Z to have the subtracted percentage of X calculated by the percentage number in Y.

I hope that made sense.
Thanks,
Bill

My Product Information:
Acrobat Pro 8.1.2, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Use Acrobat's predefined display format for percentages and enter the percentage value as a decimal. Adding the "%" converts the number to a text string. And if you want to use that text string in a calculation, you will have remove the "%" and any blanks and convert the resulting number back to a decimal value.

By the way MS Office in Excel and Access handle the percentage entry and display in this same manner.

George Kaiser

billh098
Registered: Jun 6 2009
Posts: 47
So what would be the procedure for the following:

Field Z to have the subtracted percentage of X calculated by the percentage number in Y.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Assuming field 'Y' is the discount rate, the "Custom calculation script' for field 'Z' could be:

// total purchase
var a = this.getField("Field X").value;
// discount rate of total purchase
var b = this.getField("Field Y").value;
// compute discount amount
var fDiscount = a * b;
// compute total puchase less discount, net purchase price
event.value = a - fDiscount;

George Kaiser

billh098
Registered: Jun 6 2009
Posts: 47
Thanks for your help. I could not get it to work though. This is what I have:

In field X I have the sales price of $10,000. (settings are set to Number)

In field Y I have the discount rate of .10. ( settings are set to Percentage)

In field Z I have your code in Custom Calculation Script and settings are set to Number. I should be getting in this field the adjusted sales price after the 10% off but it does nothing.

Thanks,
Bill
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Are you getting any errors in the JavaScript Debugging console?

The text between the quote marks for the 'this.getField().value' should be the field's name as it appears in the field's property window.

George Kaiser

billh098
Registered: Jun 6 2009
Posts: 47
Ah! I forgot to delete the words "Field" from your formula. My names were just " X" "Y" and "Z". Worked great! thanks so much.

One more thing; is there anyway to make the X percentage field default to 0?

Bill
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
You can set the default value for the form field on the 'Options' tab.

George Kaiser

billh098
Registered: Jun 6 2009
Posts: 47
Thanks so much ...You are the Man!
Bill
billh098
Registered: Jun 6 2009
Posts: 47
gkaiseril,
You probably know this so I thought I would ask.

I have 3 fields and then another field that is set to Average and those 3 fields are picked. The problem is if I have just one of the 3 fields filled out, the average field still divides it by 3.

How do I get the average of, just the fields I have filled out?
Bill
nicholsx
Registered: Dec 9 2010
Posts: 2
Help I belong in Form Calculation preschool

I am trying to create a form that calculates: “Unit price” x “discount%” = “Net Price”

I would like to be able to manually enter “25” in the discount% field and have it multiply the “Unit Price” x 100- 25 x .01 and show the result as “Net Price” whereas the “25” is a user input value.

Certain I am not the first to ask this. Is there a simple script that is available for me to copy and paste from somewhere?

NOV ReedHycalog

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
I think you need to compute the amount of the discount using the discount rate and the subtract the computed discount amount from the unit price to obtain the net price.

It is always a good idea to show the rate and amount of the discount. I believe some localities require this disclosure. It may also allow for other calculations like sales tax on the amount before discount that may also be required by the location of the seller.

Have you tried using formatted fields? Like setting the discount rate to the "Percent" format. The displayed value will be 25% but the value used in the calculation will be 0.25.

Have you looked at Thom Parker's How to do (not so simple) form calculations.

George Kaiser