0

The PHP script captures the values and calculates the future value. working backwards from the last month to the first, how could I compute the investment for the previous month and display the months number and the value all the way back to the first investment (Unknown). I've already figured out that I'll have to uses a formula like this "months value = (months value)/(1 + rate)" but after that I hit a road block. basically I'm trying how to figure how much do you invest today to have a balance value of $XXX after xx years at a x% interest rate?

<?php
    // get the data from the form
    $investment = $_POST['investment'];
    $interest_rate = $_POST['interest_rate'];
    $years = $_POST['years'];

    // calculate the future value
    $future_value = $investment;
    for ($i = 1; $i <= $years; $i++) {
        $future_value = ($future_value + ($future_value * $interest_rate *.01));
    }
    // apply currency and percent formatting
    $investment_f = '$'.number_format($investment, 2);
    $yearly_rate_f = $interest_rate.'%';
    $future_value_f = '$'.number_format($future_value, 2);

?>
4

1 に答える 1

0

あなたの式は基本的にこれです:

  • X から始める
  • Y 年ごとに、X を Z% ずつ増やします

これは単純な関数です: result = X * (1+Z%)^Y

つまり、求める具体的な結果があり、年数と利率がわかっているので、基準額を計算したいとします。簡単: X = 結果 / (1+Z%) ^ Y

変数名を使用すると、
$investment = $future_value / pow(1+$interest_rate/100,$years);

終わり!

于 2013-09-13T20:12:00.920 に答える