PV function works in code pen as expected but not in PDF
Howdy folks, I hope this message finds you well this morning/afternoon/evening.
I'm trying to implement the JS logic I have here in this codepen that is calculating the present value of a loan based on a corresponding payment, and then dividing that total by a the inverse of a downpayment % which is ( 1 - downPaymentRate ).
In the codepen I'm getting expected dollar amounts +/- a few cents in comparison to the PV formula as it exists in an excel spreadsheet. For whatever reason when I implement this same function in the adobe PDF it's giving me a value thats off by over $8000. I'm not sure what the difference is in the formula perhaps someone else has seen this problem before.
the codepen: https://codepen.io/buff4eyes/pen/XWoLQVN
the code in my PDF:
function calculatePV(rate, nper, pmt, fv) {
// Calculate the present value using the formula
var pv = fv / Math.pow(1 + rate, nper);
// If there are periodic payments (pmt), subtract them from the present value
if (pmt) {
pv -= pmt * (1 - Math.pow(1 + rate, -nper)) / rate;
}
return pv;
}
var adjustedListPrice = getField("adjustedListPrice");
var downPaymentRate = Number(getField("DOWNPAYMENTRow2").value)
var LLMonthlyPayment = Number(getField("LLPMT2").value);
var rate = Number(getField("MARKETRATERow2").value);
var PVRate = (rate / 12);
var nper = 360;
var calculatedPV = calculatePV(PVRate, nper,-LLMonthlyPayment, 0);
var denominator = (1 - downPaymentRate).toFixed(3);
adjustedListPrice.value = (calculatedPV / denominator).toFixed(2);when I use the same values as shown in the js file of the codepen I get a substantially different answer. Is the Math.pow function operating differently in the pdf? I'm so confused.
