2013-11-02 22 views
0

나는 거의 일하고 있지만 어떤 이유로 갚아야 할 차트에 나머지가있다. 반올림 문제 일지 모르지만 확실하지 않습니다. 누구든지이 경험이 있으면 월별 지불 기능을 살펴볼 수 있습니다. 이것은 내가 개발 한 작은 backbone.js 응용 프로그램의 일부이며, 당신은 정수가 실제로없는 내가하는 index.js _total에 라인 (133)에 그것을 볼 수 http://rvb.chrismills.la자바 스크립트 저당 계산기 기능

// Calculate mortgage based on selected values 
calculateRBV: function() { 
    var _this = this; 
    // Make sure the correct downpayment is displaying 
    _this.calculateDP(); 
    var _calcRent = $('#rvbRent').val(); 
    var _calcVal = $('#rvbBuy').val(); 
    var _calcDpPercent = $('#rvbDP').val()/100; 
    var _calcDpAmt = _calcVal * _calcDpPercent; 
    var _calcFinanced = _calcVal - _calcDpAmt; 
    var _calcLength = $('#rvbTerm').val() * 12; 
    var _calcRate = $('#rvbRate').val()/100/12; 
    var _calcTaxes = $('#rvbTaxes').val(); 
    var _calcHpChange = $('#rvRentChangeVal').val(); 
    var _calcRentChange = $('#rvRentChangeVal').val(); 
    var _monthlyPayment = Math.floor((_calcFinanced*_calcRate)/(1-Math.pow(1+_calcRate,(-1*_calcLength)))*100)/100; 
    var _totalPayments = _monthlyPayment * _calcLength; 
    var _totalInterest = _totalPayments - _calcVal; 
    var _totalRent = _calcRent * _calcLength; 
    $('#rvbMonthly span').html(_this.formatNumber(_monthlyPayment)); 
    $('#rvbTotal span').html(_this.formatNumber(_totalPayments)); 
    $('#rvbInterest span').html(_this.formatNumber(_totalInterest)); 
    _this.buildAmortizationChart(_calcFinanced, _monthlyPayment, _calcLength, _calcRate); 
    $('#rvbGraph').stop().slideDown(250); 
    $('#amortizationChart').stop().slideDown(250); 
}, 

// Build Amortization Chart 
buildAmortizationChart: function(total, monthlyPayment, months, rate) { 
    var _this = this; 
    $('#amortizationChart tbody').html(''); // clear previous 
    var _total = total; 
    var _monthlyPayment = monthlyPayment; 
    var _months = months; 
    var _rate = rate; 
    for(var i=1; i<=months; i++) { 
     var _interest = _total * _rate; 
     var _principal = _monthlyPayment - _interest; 
     _total = _total - _principal; 
var aRow = ''; 
aRow += '<tr>'; 
aRow += '<td width="20%">'; 
aRow += i; 
aRow += '</td>'; 
aRow += '<td width="20%">'; 
aRow += '$' + _monthlyPayment; 
aRow += '</td>'; 
aRow += '<td width="20%">'; 
aRow += '$' + _this.formatNumber(_principal); 
aRow += '</td>'; 
aRow += '<td width="20%">'; 
aRow += '$' + _this.formatNumber(_interest); 
aRow += '</td>'; 
aRow += '<td width="20%">'; 
aRow += '$' + _this.formatNumber(_total); 
aRow += '</td>'; 
aRow += '</tr>'; 
$('#amortizationChart tbody').append(aRow); 
} 
}, 
+0

jsfiddle.net에서 라이브 데모를 생성하십시오. – charlietfl

+0

어떤 변수에 여분의 나머지가 더 정확하게 표시 될 수 있습니까? – pax162

+0

또는 js 파일로 모든 js 파일을 컴파일 할 필요가 없도록 링크를 클릭하면됩니다. – user1572796

답변

1

OK 행동에 그것을 볼 수 있습니다 :

당신이 소수의 특정 번호를이 게시물을보고 싶다면,

_total = Math.round(_total - _principal); 

을 또는 : 당신이 정수를 얻고 싶다면

_total = _total - _principal; 

, 당신은이 작업을 수행 할 수 있습니다,667,462,156을

남은 분은이게 맞습니까?

+0

입니다. 감사합니다. – user1572796