Thursday, July 3, 2014

Javascript Function to calculate future value of an investment..

// Function to calculate future value of an investment..

function fv(rate, per, nper, pmt, pv) {

    nper = parseFloat(nper);

    pmt = parseFloat(pmt);

    pv = parseFloat(pv);

    rate = eval((rate) / (per * 100));

    if ((nper == 0)) {
        //(pmt == 0) ||
        alert("Why do you want to test me with zeros?");

        return (0);

    }

    if (rate == 0) // Interest rate is 0
    {

        fv_value = -(pv + (pmt * nper));

    }

    else {

        x = Math.pow(1 + rate, nper);

        // y = Math.pow(1 + rate, nper);

        fv_value = -(-pmt + x * pmt + rate * x * pv) / rate;

    }

    fv_value = conv_number(fv_value, 2);

    return (fv_value);

}


//end of future value

No comments:

Post a Comment