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

Percentage Calculation Trouble

New Here ,
Feb 13, 2020 Feb 13, 2020

Hello, 

I am having an issue with percent text fields double/triple/quadruple/etc calculating when I use a custom script to divide the field by 100 or multiply by .01 to stop the automatic "multiply value by 100"

I am able to make the first field calculation work (I'll call that "FieldA"), so that when I enter "1" it converts it to 1.00% not 100%. But when I do the same calculation in the next percent text field (I'll call that "FieldB"), it will calculate it correctly, but will multiply "FieldA" again to the value 0.01%

When I have a third field (I'll call that "FieldC") it will work for "FieldC" but it will calculate "FieldB" again to .01 & "FieldA" again to .0001

 

I am using...      event.value = this.getField("FieldA").value*.01  for FieldA   event.value = this.getField("FieldB").value*.01  for FieldB & event.value = this.getField("FieldC").value*.01  for Field C

Hopefully that makes sense. Thank you!!

TOPICS
How to , PDF forms
1.1K
Translate
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 ,
Feb 13, 2020 Feb 13, 2020

So, you're fighting the field formatting. Not a good idea. I would suggest removing the formatting entirely and then figure out how you want the calculations to work. The number scheme need to be consistent all the way though. 

 

So the formatting only affects how the number is displayed to the user, not the actual value. Once you figure out the calculations, then you can create a custom format script that will work for how you want the value displayed to the user.

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

Translate
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 ,
Feb 13, 2020 Feb 13, 2020

Okay, so if I want the field to display 75.00% when the user enters 75 into the field. How would I do that? Is that possible? 

Translate
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 ,
Feb 13, 2020 Feb 13, 2020

Yes, nearly any format you can think of is possible, but anthing that is non-standard requires a script

 

Enter this into the Custom format script for the field:

 

event.value = util.printf("%0.2f%",event.value); 

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

Translate
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 ,
Feb 14, 2020 Feb 14, 2020

Hi Thom,

I entered that script for the first text field. I entered 1.5 and it converted it to 1.50%. When I entered 1.5 into the 2nd text field, it converted it to 1.50% but automattically changed the first field box to 1.#R%. When I enter 1.5 into the third text field, it converts to 1.50% but changes text field 2 also to 1.#R%

 

Translate
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 ,
Feb 14, 2020 Feb 14, 2020

Does you use any calculation at the fields?

Translate
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 ,
Feb 14, 2020 Feb 14, 2020

I do not believe so. I put "Format" to "None" 

And under the "Calculate" tab - I selected "Custom Calculation Script" and put the above script you told me to use. 

Translate
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 ,
Feb 14, 2020 Feb 14, 2020

Why does you use the script there?

Translate
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 ,
Feb 14, 2020 Feb 14, 2020

Oh, so I go under the "Format" tab and put it under the "Custom Format Script" ? 

Translate
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 ,
Feb 14, 2020 Feb 14, 2020

Also, when I put that script only into one text field, it will work. But as soon as I enter anything into any other field. Even if I type a letter into a text field, it will change the field with the script to "1.#R%"

Translate
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 ,
Feb 17, 2020 Feb 17, 2020
LATEST

The script I provided must be placed in the custom format script. If used in the format script, and no where else, then it is impossible for it to affect any other field.

 

You see, the format script only affects the appearance of the field, not anything else. So if the other fields are being affected, then the script is not in the custom format. Please ensure that is only in the custom format. 

 

Also, the "1.#R%" output is caused by the value of the field not being a number.   This script can only be used to format numbers, nothing else.

 

 

 

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

Translate
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