Adobe Acrobat Java Script Percent Equation Problem
Please help me finish this script to result in an answer that is a percent with 2 decimal points.
Here's one way:
(function () {
// Get the field values, as numbers
var v1 = +getField("AmountActualstoDateRestaurant2").value;
var v2 = +getField("AmountPriorYearToDateVarRestaurant3").value;
var v3 = +getField("AmountPriorYearToDateVarRestaurant3").value;
// Calculate the value
if (v3 !== 0) {
event.value = util.printf("%.2f", 100 * (v1 - v2) / v3) + "%";
} else {
// Display nothing when denominator is zero
event.value = "";
}
})();
If you set up the field with a percent format, just leave out the multiplication by 100 and the addition of the percent sign:
event.value = util.printf("%.2f", (v1 - v2) / v3);
That worked PERFECTLY. Thanks.
Brad Sommer
CKE Restaurants
Office 1314 259 6239
Cell 13146800380
From: George Johnson forums@adobe.com
Sent: Friday, April 13, 2012 12:23 PM
To: bsommerhardees
Subject: Re: Java Script Problem - percent and decimal points Java Script Problem - percent and decimal points
Re: Java Script Problem - percent and decimal points
created by George Johnson <http://forums.adobe.com/people/George_Johnson>in
JavaScript - View the full
North America
Europe, Middle East and Africa
Asia Pacific