CODE FOR FUNCTION NPER

<script language="JavaScript">

<!--

// Function to calculate total number of payments.

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

{

fv = parseFloat(fv);

pmt = parseFloat(pmt);

pv = parseFloat(pv);

per = parseFloat(per);

if (( per == 0 ) || ( pmt == 0 )){

alert("Why do you want to test me with zeros?");

return(0);

}

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

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

{

nper_value = - (fv + pv)/pmt;

}

else

{

nper_value = Math.log((-fv * rate + pmt)/(pmt + rate * pv))/ Math.log(1 + rate);

}

nper_value = conv_number(nper_value,2);

return (nper_value);

}

function conv_number(expr, decplaces)

{ // This function is from David Goodman's Javascript Bible.

var str = "" + Math.round(eval(expr) * Math.pow(10,decplaces));

while (str.length <= decplaces) {

str = "0" + str;

}

var decpoint = str.length - decplaces;

return (str.substring(0,decpoint) + "." + str.substring(decpoint,str.length));

}

// --></script>

Go to my Homepage