您现在的位置:首页 >> 前端 >> 内容

利息计算代码,预期收益计算公式

时间:2017/9/7 9:30:00 点击:

  核心提示:利息计算代码,预期收益计算公式var sys = { //预期收益计算公式 Interest : { /** * 按月付息到期还本 */ interest: function(amount...

利息计算代码,预期收益计算公式

var sys = {
	//  预期收益计算公式
	Interest : {
		/**
		 * 按月付息到期还本
		 */
		interest: function(amount, year_ratio, month) {

			var month_ratio = year_ratio / 100 / 12;
			var total_interest = amount * month_ratio * month;
			return {
				total_interest: total_interest.toFixed(2),
				total: (amount + total_interest).toFixed(2)
			};
		},

		/**
		 * 一次性还本付息
		 */
		bullet_repayment: function(amount, year_ratio, month, days) {
			var month_ratio = year_ratio / 100 / 12;
			var day_ratio = year_ratio / 100 / 365;
			var total_interest = amount * month_ratio * month + amount * day_ratio * days;
			return {
				total_interest: total_interest.toFixed(2),
				total: (amount + total_interest).toFixed(2)
			};
		},

		/**
		 * 等额本息
		 */
		equal_installment: function(amount, year_ratio, month) {
			var month_ratio = year_ratio / 100 / 12;
			var repay_monthly = amount * ((month_ratio * Math.pow(1 + month_ratio, month)) / (Math.pow(1 + month_ratio, month) - 1));
			var total_interest = repay_monthly * month - amount;
			return {
				total_interest: total_interest.toFixed(2),
				repay_monthly: repay_monthly.toFixed(2),
				total: (amount + total_interest).toFixed(2)
			};
		},

		/**
		 * 等额本金
		 */
		equal_principal: function(amount, year_ratio, month) {
			var month_ratio = year_ratio / 100 / 12;
			var principal_monthly = amount / month;
			var total_interest = 0;
			var repay_first = principal_monthly;
			for(var i = 0; i < month; i++) {
				total_interest += ((amount - principal_monthly * i) * month_ratio);
				if(i === 0) {
					repay_first += total_interest;
				}
			}
			return {
				total_interest: total_interest.toFixed(2), // 总利息
				repay_first: repay_first, // 首次还款金额
				total: (amount + total_interest).toFixed(2) // 本息合计
			};
		},

		calc: function(amount, year_radio, month, days, repayment) {
			var result,
				othis=this;
			if(repayment === 'INTEREST') {
				result = sys.Interest.interest(amount, year_radio, month);
			} else if(repayment === 'BULLET_REPAYMENT') {
				if(month !== 0) {
					result = sys.Interest.bullet_repayment(amount, year_radio, month, 0);
				} else {
					result = sys.Interest.bullet_repayment(amount, year_radio, 0, days);
				}
			} else if(repayment === 'EQUAL_INSTALLMENT') {
				result = sys.Interest.equal_installment(amount, year_radio, month);
			} else if(repayment === 'EQUAL_PRINCIPAL') {
				result = sys.Interest.equal_principal(amount, year_radio, month);
			}
			return result;
		}
	}
}

demo:

sys.Interest.calc(10000,4,1,0,'BULLET_REPAYMENT').total_interest

作者:网络 来源:NikcroBlog
  • 上一篇:Sass语法之循环
  • 下一篇:错误处理机制