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

Calculate list price and discount to get buy price

boourns
Registered: Apr 11 2011
Posts: 10
Answered

I currently have a table with three columns - List Price, Discount and Buy Price. The aim of the form is to have a list price and if a discount on the list price needs to be shown, you just enter in the discount and the buy price is automatically calculated to show list price less the discount percentage.
 
In both List Price and Buy Price I selected the Number format and in Discount I selected the Percentage Format.
 
At the moment to change the percentage amount I have to type .50 for 50% instead of just putting in 50 but I've been browsing through the forums and changed the custom format script to
if (event.value != "") {
event.value = event.value + "%"
}

 
My current Buy Price calculation is as follows;
// total purchase
var a = this.getField("ListPrice16").value;
// discount rate of total purchase
var b = this.getField("Discount12").value;
// compute discount amount
var fDiscount = a * b;
// compute total puchase less discount, net purchase price
event.value = a - fDiscount;

  
What is the correct code to use so that I can keep my nicely formatted percentage table as well as correct Buy Price calculations?

My Product Information:
Acrobat Pro 10.0, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Accepted Answer
Keep the format script, change the field's format from Percentage to Number, and change this line:
var fDiscount = a * b;
to this:
var fDiscount = a * (b/100);

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

boourns
Registered: Apr 11 2011
Posts: 10
This is perfect! Thank you so much for your help :)