I've created a form in Adobe X that has a few calculated fields. For ease of conversation, we'll call them Field A, Field B and Field C (see below). I need Fields A and B to be rounded to the nearest whole number so that Field C is also a whole number. I've tried formatting Fields A and B to show no decimals but the calculaton is still being performed on the non-rounded numbers. Can anyone help with this? Thanks.
Field A - Field B = Field C
You'll have to use JavaScript. The code for the custom calculation script for your example would be:
// Cust calculation script
(function () {
// Get the field values, rounded to nearest integer
var v1 = Math.round(+getField("fieldA").value);
var v2 = Math.round(+getField("fieldB").value);
// Set this field value to the difference
event.value = v1 - v2;
})();
Replace "fieldA" and "fieldB" in the code above with the actual field names.
Well this is the way JavaScirpt works and for many calculations the unrounded nubmers are needed for the calculaitons.
You need to set the value of the calculated field to the rounded value.
I would use a custom calculation script and you can use JavaScript's "Math.round" method or Acrobat's "util.printf" method.
event.value = Math.round(event.value);
event.value - util.printf("%,1 .0f", event.value);
George I must be missing something. I added the math.round functions as shown in your example but now it doesn't calculate at all. Can you look at the coding shown below and let me know where I went wrong? Thanks.
Updated Coding:
(function(){
var totalMiles = math.round(+this.getField("Total Miles DrivenRow1").value);
var homeMiles = math.round(+this.getField("Home Base MilesRow1").value);
var diff = totalMiles - homeMiles;
if (diff<0) diff = 0;
event.value = diff;})();
Original Coding:
var totalMiles = +this.getField("Total Miles DrivenRow1").value;
var homeMiles = +this.getField("Home Base MilesRow1").value;
var diff = totalMiles - homeMiles;
if (diff<0) diff = 0;
event.value = diff;
North America
Europe, Middle East and Africa
Asia Pacific