如何格式化指数?

时间:2018-03-20 00:27:23

标签: c# math

public partial class frmValidate : Form
{
    const double ANNUAL_INTEREST_RATE = .05;
    const double YEARS = 10;

    public frmValidate()
    {
        InitializeComponent();
    }

    private void btnCalc_Click(object sender, EventArgs e)
    {
        double dblFutureValue;
        if (double.TryParse(txtFutureValue.Text, out dblFutureValue))
        {
        }
    }

    private void btnReset_Click(object sender, EventArgs e)
    {
        txtFutureValue.Clear();
        lblPresentValue.Text = "";
        txtFutureValue.Focus();           
    }

    private void frmValidate_Load(object sender, EventArgs e)
    {
        lblInterestRate.Text = ANNUAL_INTEREST_RATE.ToString();
        lblYears.Text = YEARS.ToString();
    }

    private void PresentValue (double dblFutureValue)
    {
        double dblPresentValue;
        dblPresentValue = dblFutureValue / (1 + ANNUAL_INTEREST_RATE) * YEARS;
        dblPresentValue.ToString("C");
    }
}

我有一个叫做现值的方法,公式应该是:

PresentValue = Future Value / (1+r)^n

我知道您使用Math.Pow()方法,但我无法弄清楚将它放在哪里。

1 个答案:

答案 0 :(得分:2)

private void PresentValue (double dblFutureValue)
    {
        double dblPresentValue;
        double r = Math.Pow(1 + ANNUAL_INTEREST_RATE,YEARS);
        dblPresentValue = dblFutureValue / r;
        dblPresentValue.ToString("C");
    }