JavaScript中的PMT功能 [英] PMT function in Javascript

查看:170
本文介绍了JavaScript中的PMT功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Javascript中使用Excel PMT函数. 该参数将为

I want to use Excel PMT function in Javascript. The parameter would be

Pmt(利率,付款次数,PV,FV,类型)

Pmt( interest_rate, number_payments, PV, FV, Type )

interest_rate : the interest rate for the loan.
number_payments : the number of payments for the loan.
PV : the present value or principal of the loan.
FV : It is the future value or the loan amount outstanding after all payments have been made. 

Type is : It indicates when the payments are due. Type can be one of the following values:
 0, 1

您可以参考: http://www.techonthenet.com/excel/formulas/pmt.php

这是我使用的代码,我被卡在最后一个参数中. 类型是" 0或1.请如何影响计算.

this is the code I use, I am stuck in last parameter. Which is "type is" 0 or 1. How it effect the calculations please.

function PMT (ir, np, pv, fv ) {
 /*
 ir - interest rate per month
 np - number of periods (months)
 pv - present value
 fv - future value (residual value)
 */
 pmt = ( ir * ( pv * Math.pow ( (ir+1), np ) + fv ) ) / ( ( ir + 1 ) * ( Math.pow ( (ir+1), np) -1 ) );
 return pmt;
}

我需要用纯Javascript而不是jQuery.

I need it in plain Javascript and not in jQuery please.

推荐答案

了解Type参数影响的最简单方法是尝试以下值:年利息= 12%,月数= 1,现值= 100

The easiest way to understand the impact of the Type parameter is to try the following values: Annual Interest = 12%, # of Months = 1, Present Value = 100

当Type = 0(默认值)时,PMT()函数将产生101

When Type=0 (the default), the PMT() function will yield 101

当Type = 1时,PMT()函数将产生100

When Type=1, the PMT() function will yield 100

在Type = 0的情况下,利息被计算为1个月,因为假定付款在月底.对于Type = 1,由于付款是在月初进行的,因此利息计算为0个月.

With Type=0, the interest is computed for 1 month because the payment is assumed to be at the end of the month. For Type=1, the interest is computed for 0 months because the payment is at the beginning of the month.

这篇关于JavaScript中的PMT功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆