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

Calculate percent Pdf

Community Beginner ,
Mar 08, 2021 Mar 08, 2021

Copy link to clipboard

Copied

Hi, 

Im trying to create a script in my pdf

A (old price)  B(new price) = %discount

 

example : old $98  new $75 = 23.47%

Can anybody help me please?

TOPICS
JavaScript , PDF forms

Views

566

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 , Mar 08, 2021 Mar 08, 2021

If you use this script you have to check whether "a" is zero, or you'd get an error message (or a strange result). Replace the last line with this:

 

if (a==0) event.value = "";

else event.value = (a-b)/a;

 

Votes

Translate

Translate
Community Expert ,
Mar 08, 2021 Mar 08, 2021

Copy link to clipboard

Copied

To calculate decreasing percentage (23.47%) from 98 and 75 would be:

(98-75)/98

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 Beginner ,
Mar 08, 2021 Mar 08, 2021

Copy link to clipboard

Copied

Thank you, how do I write it in my script so it automatically calculates?

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 ,
Mar 08, 2021 Mar 08, 2021

Copy link to clipboard

Copied

I don't know where you want calculation or your field names so Il use example and you change it later.

As "Custom calculation script" of field where you want to show percentage use this:

var a = Number(this.getField("Text1").value);
var b = Number(this.getField("Text2").value);
event.value = (a-b)/a;

Change field names if needed.

 

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 Beginner ,
Mar 08, 2021 Mar 08, 2021

Copy link to clipboard

Copied

Fantastic! Thank you so much! 🙂

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 ,
Mar 08, 2021 Mar 08, 2021

Copy link to clipboard

Copied

If you use this script you have to check whether "a" is zero, or you'd get an error message (or a strange result). Replace the last line with this:

 

if (a==0) event.value = "";

else event.value = (a-b)/a;

 

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 Beginner ,
Mar 08, 2021 Mar 08, 2021

Copy link to clipboard

Copied

LATEST

Thank you so much

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