简体   繁体   English

我知道我在用复利公式做错了

[英]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.

相关问题 如何在Java表达式中编写复利公式? - How would I write the formula for compound interest in an expression in Java? 不知道我在做什么错(布尔标志) - Not sure what i'm doing wrong here (Boolean flag) Java的Euler挑战1-我做错了什么? - Euler Challenge 1 in Java - I'm doing something wrong? “ For”循环停止正常工作(或者我做错了什么) - “For”-loop ceases to work properly (or I'm doing something wrong) Matcher跳过第一场比赛? 还是我做错了什么 - Matcher its skipping the first match ? Or i'm doing something wrong 我正在向某人的现有Swing代码添加一个组合框。 我在这里做错了什么? - I'm adding a combobox to someone's existing Swing code. What am I doing wrong here? 我收到看似简单的 Java 代码的奇怪错误。 我在这里做错了什么? - I'm getting weird errors for seemingly simple Java code. What am I doing wrong here? Path的.relativize()文档中的错误,还是我在这里公然做错了什么? - Bug in Path's .relativize() documentation or am I doing something blatantly wrong here? getSource()-我在做什么错呢? - getSource() - What am I doing wrong here? 我正在尝试使用Java更新oracle数据库中的密码。 难道我做错了什么? - I'm trying to update my password in oracle database using Java. Am I doing something wrong?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM