Excel - PMT - NaN and Infinity messages
Hello!
I use this snipet, to calculate PMT.
-
- function PMT(i, n, p) {
- return i * p * Math.pow((1 + i), n) / (1 - Math.pow((1 + i), n));
- }
- function CalculatePMTFromForm(idLoanAmount, idAnnualInterestRate, idMonths, idResult) {
- var i = jQuery('#' + idAnnualInterestRate).val() / 1200;
- var n = jQuery('#' + idMonths).val();
- var p = jQuery('#' + idLoanAmount).val();
- var pmt = PMT(i, n, -p);
- jQuery('#' + idResult).val(pmt.toFixed(2));
- }
- function performCalc() {
- CalculatePMTFromForm('LoanAmount', 'InterestRate', 'Months', 'Payment');
- }
- jQuery(document).ready(function() { performCalc(); jQuery('.calc').keyup(performCalc); });
-
- The result shown in this input box:
- <td><input id="Payment" size="11" type="text" value="" /></td>
If i delete the input box value or get negative value, or start the
value with 0, i get an error message in the result input box (NaN or
Infinity)
Could anyone help me to disable, or change this message text?
Thank you.