房贷计算公式
Posted Rander.C
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了房贷计算公式相关的知识,希望对你有一定的参考价值。
房贷计算公式
#include <iostream>
//根据贷款额度、年利率、贷款月数获得月供
float getMonthlyPayment(float loan, float yearRate, int months)
float month_rate = yearRate / 12 ;
float up= loan * month_rate;
float comm_base = 1.0f;
for(int i=0; i < months; i++)
comm_base *= (1 + month_rate);
return (up * comm_base) / (comm_base - 1.0f);
//根据贷款额度、年利率、月供获得还款月数
int getPayMonths(float loan, float yearRate, float monthPayment)
float month_rate = yearRate / 12 ;
float c = monthPayment/(monthPayment - loan * month_rate);
int months = 0;
float rate = 1.0f;
while (1)
rate *= (1+month_rate);
if(rate >= c)
break;
months++;
return months;
int main()
printf("monthlyPayment %f\\n",getMonthlyPayment(1000000,0.05285,360));
printf("PayMonths %d\\n",getPayMonths(1000000.57,0.05285,5543.726074));
return 0;
以上是关于房贷计算公式的主要内容,如果未能解决你的问题,请参考以下文章