0

我几乎可以正常工作,但由于某种原因,摊销表上有剩余。我认为这可能是四舍五入的问题,但不确定。如果有人有这方面的经验,你可以看看每月支付功能。这是我正在开发的一个小型backbone.js 应用程序的一部分,您可以在运行中看到它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);
}
}, 
4

1 回答 1

1

好的,我可以看到 index.js_total中的第 133 行确实不是整数:

_total = _total - _principal;

如果你想得到一个整数,你可以这样做:

_total = Math.round(_total - _principal);

或者,如果您想获得特定的小数位数,请参阅这篇文章:在 JavaScript 中格式化具有恰好两位小数的数字

这就是你说的余数吗?

于 2013-11-02T17:09:32.807 回答