[英]I know I'm doing something wrong here with compound interest formula
Background: doing a budget portfolio program and I am trying to add in a compound interest calculator for a client's savings. 背景:做一个预算投资组合计划,我试图添加一个复利计算器以节省客户的钱。 Running into some problems here.
在这里遇到一些问题。 So here is the formula I currently have.
所以这是我目前拥有的公式。
double comprinc= 25*(Math.pow((1+.05/12),(12*year)));
double futurev = saving1*(Math.pow((1+.05/12),((12*year)-1))/(.05/12));
This is the following formula broken down into two halves 以下是分解成两半的公式
Total = [ P(1+r/n)^nt ] + [ PMT * (((1 + r/n)^nt - 1) / (r/n)) ] or 总数= [P(1 + r / n)^ nt] + [PMT *(((1 + r / n)^ nt-1)/(r / n))]或
Total = comprinc + futurev 总计=企业+未来v
P= principle =25 P =原理= 25
r= rate=.05 r =比率= .05
n= number of time interest is compounded n =计息时间数
t= the number of years =5( have year currently set to 5) t =年数= 5(当前年份设置为5)
PMT= initial savings=saving1=25 PMT =初始节省=节省1 = 25
The problem is that I am testing this against an official compound interest calculator and the answers I'm getting are no where close. 问题是我正在用官方的复利计算器对它进行测试,而得到的答案远非如此。
For example the answer that my program reads out is $7700.28 after 5 years should be $1739.32 例如,我的程序读出的答案是5年后的$ 7700.28应该是$ 1739.32
I think the key is the -1 is not part of the exponent. 我认为关键是-1不是指数的一部分。 I am also trying to simplify here, by reducing calculations and parentheses.
我也在尝试通过减少计算和括号来简化。
double intPerPeriod = .05/12;
double numPeriods = 12*year;
double comprinc= 25*(Math.pow(1+intPerPeriod,numPeriods));
double futurev = saving1*(Math.pow(1+intPerPeriod,numPeriods)-1)/intPerPeriod;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.