• Global community
• Language:
• Deutsch
• English
• EspaÃ±ol
• FranÃ§ais
• PortuguÃªs
• æ—¥æœ¬èªžã‚³ãƒŸãƒ¥ãƒ‹ãƒ†ã‚£
Dedicated community for Japanese speakers
• í•œêµ­ ì»¤ë®¤ë‹ˆí‹°
Dedicated community for Korean speakers
Exit
• Round number to highest integer based on calculate...

# 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

614

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 Expert , Nov 06, 2018 Nov 06, 2018

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.

5 Replies 5
Community Expert ,
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

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.

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
LEGEND ,
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.

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!

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!