# Round number to highest integer based on calculated text field

Community Beginner ,
Nov 06, 2018 Nov 06, 2018

Copied

I'm not a java guy, but I've gone over the internet threads and couldn't find the exact fix to my problem. I'm using acrobat pro dc. I'm using a text field formatted to number with the following calculation:

(A+B+C+D)/4 in the simplified field notation.

I now need this calculation to always round up to the highest integer. Here are a few examples:

12.1=13

12.5=13

12.9=13

etc.

From what I've read, everyone says to use Math.ceil(); however, I cannot enter an actual number with Math.ceil() since I don't know the numbers because it's calculating them based on user input from other fields.

I believe it has something to do with inputting the following math equation:

`( x + y - 1 ) / y`

I just don't know how to implement it. Also, does it matter if I have number set to 0 or 2 for decimal places if I'm just looking for the higher integer?

Any custom calculation or validation scripts I can use to fix this? Thanks!

TOPICS
Acrobat SDK and JavaScript, Windows

Views

205

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Adobe Community Professional , Nov 06, 2018 Nov 06, 2018
You'll need to use JavaScript for the calculation. // Here's the calculation in Acrobat JavaScriptvar A = this.getField("AField").value;var B = this.getField("BField").value;var C = this.getField("CField").value;var D = this.getField("DField").value;event.value = Math.ceil((A+B+C+C)/4);The "AField", "BField", etc. are placeholders for the actual field names on your form.

Likes

5 Replies 5
Nov 06, 2018 Nov 06, 2018

Copied

You'll need to use JavaScript for the calculation.

// Here's the calculation in Acrobat JavaScript

var A = this.getField("AField").value;

var B = this.getField("BField").value;

var C = this.getField("CField").value;

var D = this.getField("DField").value;

event.value = Math.ceil((A+B+C+C)/4);

The "AField", "BField", etc. are placeholders for the actual field names on your form.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
Nov 06, 2018 Nov 06, 2018

Copied

When I enter the script, it seems to not change anything. Below is my exact script:

var A = this.getField(PM_RAW_TOTAL).value;

var B = this.getField(PM_RAW_TOTAL_2).value;

var C = this.getField(PM_RAW_TOTAL_3).value;

var D = this.getField(PM_RAW_TOTAL_4).value;

event.value = Math.ceil((A+B+C+D)/4);

^^^(I'm assuming you meant D instead of C twice?)

Also, when I delete the total number out of the text field, it doesn't recalculate/repopulate.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 06, 2018 Nov 06, 2018

Copied

This line:

var A = this.getField(PM_RAW_TOTAL).value;

Should be this:

var A = this.getField("PM_RAW_TOTAL").value;

Same for the others. Always check the JavaScript console (Ctrl+J) for errors that will help you troubleshoot.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
Nov 07, 2018 Nov 07, 2018

Copied

Oh shoot, I didn't even realize they had a console on here lol my bad. Thanks, the quotes fixed it!

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
Nov 07, 2018 Nov 07, 2018

Copied

LATEST

Awesome! This worked perfect, thanks!

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more