英文:
How to calculate Excel PV function in Java
问题
这是一个用于计算现值(PV)的Excel公式
calculatePV(double rate, int nper, double pmt, double fv, int type)
我如何在Java中使用给定的参数进行相同的计算?
英文:
This is an excel formula to calculate Present Value (PV)
PV (rate, nper, pmt, [fv], [type])
How do I calculate the same in Java with the mentioned parameters?
答案1
得分: 1
public static double pv(double rate, double numberOfPeriod, double payment) {
double retval = 0;
boolean t = false;
if (rate == 0) {
retval = -1*((numberOfPeriod*payment));
}
else {
double r1 = rate + 1;
retval =
(( ( 1 - Math.pow(r1, numberOfPeriod) ) / rate ) * (t ? r1 : 1) * payment - 0)
/
Math.pow(r1, numberOfPeriod);
}
return retval;
}
其中,t 是类型 - 支付时机。0 = 期末,1 = 期初。默认值为 0。
英文:
public static double pv(double rate, double numberOfPeriod, double payment) {
double retval = 0;
boolean t = false;
if (rate == 0) {
retval = -1*((numberOfPeriod*payment));
}
else {
double r1 = rate + 1;
retval =
(( ( 1 - Math.pow(r1, numberOfPeriod) ) / rate ) * (t ? r1 : 1) * payment - 0)
/
Math.pow(r1, numberOfPeriod);
}
return retval;
}
where t is type - When payments are due. 0 = end of period, 1 = beginning of period. The default is 0.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论