Excel PMT function in JS

前端 未结 3 656
-上瘾入骨i
-上瘾入骨i 2021-02-06 04:07

I found i little snipet on internet, about PMT calculate.

function PMT(i, n, p) {
 return i * p * Math.pow((1 + i), n) / (1 - Math.pow((1 + i), n));
}
function C         


        
3条回答
  •  迷失自我
    2021-02-06 04:33

    Try it like this:-

    function CalculatePMTFromForm(idLoanAmount, idAnnualInterestRate, idMonths, idResult) {
     var i = parseFloat($('#' + idAnnualInterestRate).val()) / 1200;
     var n = parseFloat($('#' + idMonths).val());
     var p = parseFloat($('#' + idLoanAmount).val());
     var pmt = PMT(i, n, -p);
     $('#' + idResult).val(pmt.toFixed(2));
    }
    

    The .val() is likely returning a string type not a number type.

提交回复
热议问题