• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit Search
0

Need help with calculation field

New Here ,
Nov 25, 2022 Nov 25, 2022

Copy link to clipboard

Copied

Hello all, I recently got the trial for adobe acrobat pro as I want to make some character sheets for assorted games easier to use. I am having issues with rounding, as in i do not understand how to get the field to round up/down depending on how it should. I have tried the usual google, but all the posts I find are specific to that users need.

 

For example here is what I need/want the end result to be. Player puts the number of their ability score into the main field and then the modifier field takes that number, divides it in half, subtracts 10, then rounds down. Now so far I have the following, and each field would be slightly different since it would be pulling from a different field. (STR-10)/2

 

What I need to know, is if there is a function that I can put into the same field telling it to round up or down? Some additional information, right now I am using the simplified field notation option, let me know if it is not possible. I tried the custom calculation script with the same formula above but it just spits out a whatever number was there before no matter the number you input. So if 0 was in this field then it stays 0, so on for 1, 2, etc. adobe is pro version 2022.003.20282

TOPICS
Create PDFs , Edit and convert PDFs , General troubleshooting , How to , JavaScript , PDF forms

Views

719

Translate

Translate

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 guidelines

correct answers 1 Correct answer

Community Expert , Nov 26, 2022 Nov 26, 2022

Sorry, I forgot that you mentioned about rounding down.

 

The util.printf method rounds up decimals by default, so this is handled with the "Math.floor" function.

 

So the equation, in this case, should be expressed like this:

 

 

var abilityScore = Number(this.getField("STR FIELD").value);

  (abilityScore !=="") ? event.value = util.printf("%.0f", Math.floor((abilityScore -10)/2) ) : event.value = "";

 

 

 As for this to work, you must change in the script the correct field object name were yo

...

Votes

Translate

Translate
Community Expert ,
Nov 26, 2022 Nov 26, 2022

Copy link to clipboard

Copied

In the modifier field you may use a custom calculation script like this:

 

 

var abilityScore = Number(this.getField("STRENGTH FIELD").value);

  (abilityScore !=="") ? event.value = util.printf("%.0f", ((abilityScore - 10) / 2)) : event.value = "";

   

 

 

Here is an example file :

 

Votes

Translate

Translate

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 guidelines
New Here ,
Nov 26, 2022 Nov 26, 2022

Copy link to clipboard

Copied

tried this in my document, but it didn't do anything. i tried to adjust the script to work with the field names in my document, but it doesnt seem to work. Also when i viewed your document it looks like it is rounding up when it should be rounding down for this formula. 17 should end up being 3 but is coming out to 4. the fields i have are named STR and STRmod, so i took your formula and tried this but it doesn't seem to do anything.

 

var STRmod = Number(this.getField("STR FIELD").value);

(STRmod !=="") ? event.value = util.printf("%.0f", ((STRmod - 10) / 2)) : event.value = "";

Votes

Translate

Translate

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 guidelines
Community Expert ,
Nov 26, 2022 Nov 26, 2022

Copy link to clipboard

Copied

LATEST

Sorry, I forgot that you mentioned about rounding down.

 

The util.printf method rounds up decimals by default, so this is handled with the "Math.floor" function.

 

So the equation, in this case, should be expressed like this:

 

 

var abilityScore = Number(this.getField("STR FIELD").value);

  (abilityScore !=="") ? event.value = util.printf("%.0f", Math.floor((abilityScore -10)/2) ) : event.value = "";

 

 

 As for this to work, you must change in the script the correct field object name were you need this total to be displayed. They must be spelled in the script in the exact same way as they are spelled for the field object.

 

In the form that you shared I don't see a field with "STR FIELD" name on it; all I see is "ST Strength" or "STR" field labels.

 

More importantly, the question is: Where do you want this script to execute from?

 

For instance, If the script will be executed in the same field where the user inputs a value, then the script needs to be slightly modified. The custom calculation script that I shared is just an example based on your original post.

 

But taking a closer look at your PDF,  what I believe should work is that the user inputs the strength value in the "STR" field, and if they click on the checkbox next to the "ST Strength" field, then it will perform that calculation automatically and populate the desired value in the "ST Strength" field.

 

Is this is what you want?

Votes

Translate

Translate

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 guidelines