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

Retirement monthly calculation

Community Beginner ,
Jan 31, 2024 Jan 31, 2024

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

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

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

There is difference in result value. I have placed this code in D19 field in custom calculation 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
Community Expert ,
Jan 31, 2024 Jan 31, 2024

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

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

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