这是我的公式,没有得到正确的输出....我正在寻找有人必须贡献的月付款(以%的回报率)来获得他们的“未来价值”!!我做错了..我相信这很简单..谢谢。
//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;
}
答案 0 :(得分:0)
monthPayment = (prin*monthRate) / (1-Math.pow(1+monthRate,-numPayments))