2 Replies Latest reply on Apr 13, 2012 12:45 PM by bsommerhardees

# Java Script Problem - percent and decimal points

Adobe Acrobat Java Script Percent Equation Problem

1. event.value=(this.getField("AmountActualstoDateRestaurant2").value-this.getField("AmountPr iorYearToDateVarRestaurant3").value)/this.getField("AmountPriorYearToDateVarRestaurant3"). value;
• ###### 1. Re: Java Script Problem - percent and 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);
```
• ###### 2. Re: Java Script Problem - percent and decimal points

That worked PERFECTLY.  Thanks.

CKE Restaurants

Office 1314 259 6239

Cell 13146800380

Sent: Friday, April 13, 2012 12:23 PM

To: bsommerhardees

Subject: Java Script Problem - percent and decimal points

Re: Java Script Problem - percent and decimal points