为什么我得到错误的结果? [英] Why do I get the wrong results?
本文介绍了为什么我得到错误的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了一个C#程序来计算以不同利率计算的投资总额。
复合利息公式我正在使用:P (1 + r) n
我看不出我做错了什么。
例如:
金额:100
费率:10
年:5
随着一个计算器,答案是161.05
但是一旦我用我的程序执行它计算到100.00001
非常感谢您的帮助。
我尝试过:
I've written a C# program to calculate the total of the money invested at different amounts of interest rates.
Compound interest formula I'm using: P (1 + r )n
I cant see what I'm doing wrong.
For example:
Amount: 100
Rate: 10
years: 5
With a calculator the answer is 161.05
But once I do it with my program it calculates to 100.00001
Your help is much appreciated.
What I have tried:
double amount;
double rate;
double years;
double total;
amount = Convert.ToDouble(textBox1.Text);
rate = Convert.ToDouble(textBox2.Text);
years = Convert.ToDouble(textBox3.Text);
rate = rate / 100;
total = amount * 1 + Math.Pow(rate, years);
label1.Text = total.ToString();
推荐答案
你没有正确翻译公式。
You didn't traslate correctly the formula.
引用:
total = amount * 1 + Math.Pow(rate,years);
total = amount * 1 + Math.Pow(rate, years);
应该是
Should be instead
total = amount * Math.Pow(1 + rate, years);
这篇关于为什么我得到错误的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文