0
這裏是我的公式,沒有得到正確的輸出....我正在尋找每月的支付人將不得不貢獻(回報率%)以獲得他們的「未來價值」!我做錯了什麼..我相信這很簡單..謝謝。Flash數學「回報率」論壇?感到困惑!
//set default input text
var loanText = 100000;
var interestText = 10;
var yearsText = 1;
//restrict the input boxes to numbers and symbols
loan_txt.restrict = "0-9\\.";
interest_txt.restrict = "0-9\\.";
years_txt.restrict = "0-9\\.";
//
calculate_mc.onRollOver = function(){
this.gotoAndPlay("over");
}
calculate_mc.onRollOut = function(){
this.gotoAndPlay("out");
}
calculate_mc.onRelease = function(){
if (loan_txt.text!="" && interest_txt.text!="" && years_txt.text!=""){
loanPayments();
}else{
monthly_txt.text = "Please fill in all fields";
}
}
//
loan_txt.onSetFocus = function() {
if (loan_txt.text == loanText) {
loan_txt.text = "";
}
};
loan_txt.onKillFocus = function() {
if (loan_txt.text == "") {
loan_txt.text = loanText;
}
};
interest_txt.onSetFocus = function() {
if (interest_txt.text == interestText) {
interest_txt.text = "";
}
};
interest_txt.onKillFocus = function() {
if (interest_txt.text == "") {
interest_txt.text = interestText;
}
};
years_txt.onSetFocus = function() {
if (years_txt.text == yearsText) {
years_txt.text = "";
}
};
years_txt.onKillFocus = function() {
if (years_txt.text == "") {
years_txt.text = yearsText;
}
};
loanPayments = function(){
var loanAmount = loan_txt.text;
var interestRate = (interest_txt.text)/100;
var years = years_txt.text;
var downPayment = 0;
var monthRate = interestRate/12;
var numPayments = years*12;
var prin = loanAmount - downPayment;
monthPayment = Math.floor((prin*monthRate)/(1-Math.pow((1+monthRate),(1*numPayments)))*100)/100;
//form.NumberOfPayments.value=NumPayments
var getDec = String(monthPayment).indexOf(".");
var add0s = "";
if(String(monthPayment).length +getDec == 2){
add0s = "0";
}else if(String(monthPayment).length +getDec == 1){
add0s = "00";
}
trace(add0s);
trace(monthPayment);
monthly_txt.text = "$"+monthPayment+add0s;
}