Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

- Home
- >
- Acrobat SDK
- >
- Round number to highest integer based on calculate...

Community Beginner
,

Nov 06, 2018

Copy link to clipboard

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!

Adobe Community Professional

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.

TOPICS

Acrobat SDK and JavaScript,
Windows

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

Copy link to clipboard

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!

Adobe Community Professional

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.

TOPICS

Acrobat SDK and JavaScript,
Windows

Community Guidelines

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

andreah75641828

Nov 06, 2018
0
/t5/acrobat-sdk/round-number-to-highest-integer-based-on-calculated-text-field/td-p/10167882
5
Replies
5

Adobe Community Professional
,

Nov 06, 2018

Copy link to clipboard

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.com- Use the Acrobat JavaScript Reference Early and Often

Community Guidelines

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

Reply

Loading...

Thom Parker

Nov 06, 2018
3
/t5/acrobat-sdk/round-number-to-highest-integer-based-on-calculated-text-field/m-p/10167883#M81424
Community Beginner
,

Nov 06, 2018

Copy link to clipboard

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.

Community Guidelines

Reply

Loading...

andreah75641828

Nov 06, 2018
0
/t5/acrobat-sdk/round-number-to-highest-integer-based-on-calculated-text-field/m-p/10167884#M81425
Adobe Community Professional
,

Nov 06, 2018

Copy link to clipboard

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.

Community Guidelines

Reply

Loading...

George_Johnson

Nov 06, 2018
2
/t5/acrobat-sdk/round-number-to-highest-integer-based-on-calculated-text-field/m-p/10167885#M81426
Community Beginner
,

Nov 07, 2018

Copy link to clipboard

Copied

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

Community Guidelines

Reply

Loading...

andreah75641828

Nov 07, 2018
0
/t5/acrobat-sdk/round-number-to-highest-integer-based-on-calculated-text-field/m-p/10167886#M81427
andreah75641828
LATEST

Community Beginner
,

Nov 07, 2018

Copy link to clipboard

Copied

Awesome! This worked perfect, thanks!

Community Guidelines

Reply

Loading...

andreah75641828

Nov 07, 2018
0
/t5/acrobat-sdk/round-number-to-highest-integer-based-on-calculated-text-field/m-p/10167887#M81428
Using the Community
Experience League
Terms of Use
Privacy Policy
Cookie preferences
AdChoices
Language:

- Deutsch
- English
- Español
- Français
- 日本語コミュニティ
- Português

Copyright © 2020 Adobe. All rights reserved.