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

Custom Calculation, Script Help

Community Beginner ,
Nov 20, 2023 Nov 20, 2023

I need help with formulating a custom script for the total precentage discount for section C. (Currently shown as 1234321%). Please help. I cannot figure out the correct order.

Screenshot 2023-11-20 at 11.09.48 AM.pngexpand image

TOPICS
JavaScript , 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 ,
Nov 20, 2023 Nov 20, 2023

What script does you 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 Beginner ,
Nov 20, 2023 Nov 20, 2023

I am working in the custom calculation script within Acrobat.

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 ,
Nov 20, 2023 Nov 20, 2023

What script does you 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 ,
Nov 20, 2023 Nov 20, 2023

Did you set the field as having the Percentage option selected in the Format tab? If so, the value needs to be between 0 (0%) and 1 (100%). I would recommend switching to the Number format, instead.

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 Beginner ,
Nov 21, 2023 Nov 21, 2023

I do have this set as a Number field.

Would you be willing to look at the document?

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 ,
Nov 21, 2023 Nov 21, 2023

Sure, but this field has no calculation associated with it...

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 ,
Nov 21, 2023 Nov 21, 2023

Use this code:

 

 

var salePrice = Number(this.getField("Sale Price").valueAsString);
var listPrice = Number(this.getField("List Price").valueAsString);
if (listPrice==0) event.value = "";
else event.value = (1 - (salePrice / listPrice)) *100;

 

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 ,
Nov 21, 2023 Nov 21, 2023
LATEST

And set the field's Format to Number (with 2 decimals).

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