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

Retirement monthly calculation

Community Beginner ,
Jan 31, 2024 Jan 31, 2024

Copy link to clipboard

Copied

I am creating a formula for retirement in adobe acrobat but I am not getting correct results. 

=PMT(C17,C18,D16,-D13)

C17 is montly return rate
C18 is # of months until retirement
D16 is current savings
D13 is Amount needed in retirement 

var rate = Number(this.getField("C17").value);
var nper = Number(this.getField("C18").value);
var pv = Number(this.getField("D16").value);
var fv = -Number(this.getField("D13").value);

var pmt = (pv * rate) / (1 - Math.pow(1 + rate, -nper)) + (fv / Math.pow(1 + rate, nper));

if (this.getField("C17").value === "" || this.getField("C18").value === "")
event.value = "";
else
event.value = pmt;

TOPICS
JavaScript , PDF forms

Views

254

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 ,
Jan 31, 2024 Jan 31, 2024

Copy link to clipboard

Copied

What exactly are you getting for the results?  Why is it not correct?  Where is this code placed?

 

Just to clean up your code, in the if statement use "==" instead of "===".

However, this probably will not change your result. 

 

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

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 ,
Jan 31, 2024 Jan 31, 2024

Copy link to clipboard

Copied

There is difference in result value. I have placed this code in D19 field in custom calculation script. 

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 ,
Jan 31, 2024 Jan 31, 2024

Copy link to clipboard

Copied

So some value is being calculated, just not the correct one? 

In this case you will need to debug your calculation script. 

 

To do this, copy the first 5 lines of your script to the console window. 

Break the calculation into individual parts, and run them individually to find the issue. 

 

Here's a video tutoial on using the console window. 

https://www.pdfscripting.com/public/images/video/AcroJSIntro/AcroJSIntro_ConsoleWindow.cfm

 

 

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

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 ,
Jan 31, 2024 Jan 31, 2024

Copy link to clipboard

Copied

LATEST

I just noticed that I posted using my company account rather than my personal one. Could the administrators please delete my post? Thank you. @Thom Parker 

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