Начало
Калькуляторы
Сложный процент
Используйте JavaScript, чтобы вычислить compund проценты. Предупреждает о сомнительных данных.
Principal
Rate
Years
Amount
Interest
JavaScript Calculators: сложный процент
<!-- TWO STEPS TO INSTALL COMPOUND INTEREST: 1. Copy the coding into the HEAD of your HTML document 2. Add the last code into the BODY of your HTML document --> <!-- STEP ONE: Paste this code into the HEAD of your HTML document --> <HEAD> <SCRIPT LANGUAGE="JavaScript"> <! > <! > <!-- Begin var princ; var ratepc; var years; var rate; var power; function calcAmt(frm) { princ = eval(frm.pr.value); ratepc = eval(frm.rt.value); years = eval(frm.yr.value); rate = ratepc / 100; power = Math.pow((1 + rate), years); frm.amt.value = Math.round(princ * power * 100) / 100; frm.inter.value = Math.round((frm.amt.value - princ) * 100) / 100; } function checkInput(frm) { if (rate == 0 || rate > .3) { window.alert ("Are you sure that the interest rate is " + ratepc +"%?"); frm.rt.focus(); } if (years == 0 || years > 30) { window.alert ("Are you sure that the term is " + years + " years?"); frm.yr.focus(); } } // End --> </script> </HEAD> <!-- STEP TWO: Copy this code into the BODY of your HTML document --> <BODY> <center> <form method=get name=frm> Principal <input type=text name=pr size=10 maxlength=10 onChange=calcAmt(this.form)> Rate <input type=text name=rt size=6 maxlength=6 onChange=calcAmt(this.form)> Years <input type=text name=yr size=5 maxlength=5 onChange=calcAmt(this.form)> <br> <br> <input type=button name=calc value="Calculate" size=10 onClick=checkInput(this.form); calcAmt(this.form);> <input type=reset value="Clear"> <br> <br> Amount <input type=text name=amt size=10> Interest <input type=text name=inter size=10> </form> </center> <!-- Script Size: 2.02 KB -->