as3 / javascript贷款公式从每周汇率计算本金

时间:2013-07-30 03:02:40

标签: javascript html actionscript-3 flash math

我有一个AS3函数来计算每周还款价值,前提是我有贷款金额,利率和贷款金额的值。年数。

private function calculateRepayment(_loanAmount, _years, _interest):Number
{
    var nWeek = _years * 52;
    var nInterest = _interest/(52*100);
    var nRepayment = ( _loanAmount * nInterest *Math.pow((1+nInterest),nWeek) ) / ( Math.pow((1+nInterest),nWeek)-1 );
    return Number(nRepayment);
}

现在我需要写一个函数来计算每周还款,利率和利率的贷款额度。年数。

有关转换为AS3或javascript的公式的任何帮助都会非常感谢,我认为理论上它是loanAmount =兴趣/费率时间。

例如:

private function calculateLoanAmount(_repaymentAmount, _years, _interest):Number
{
    // var nLoanAmount:Number = ????
    return Number(nLoanAmount);
}

1 个答案:

答案 0 :(得分:0)

好的我已经解决了,这是功能:

private function calculateLoanAmount(_repayment, _years, _interest):Number
{
    var p:Number = _repayment; // weekly payment
    var i:Number = (_interest / 52) * 0.01; // weekly interest factor
    var n:Number = _years * 52; // number of weekly payments - (5 years) 5*52 = 260
    var principal:Number = (p * (1 - 1 / (Math.pow(1 + i, n)))) / i;
    principal = Math.round(roundDec(principal, 0)); // prepare for output
    return Number(principal);
}