我正在开发一个功能,该功能应该获取有关每月按揭还款金额,利率,首付等信息,并吐出用户可能负担得起的房屋成本。
公式(I think...)如下:
我在JS中有这样的代码:
function formatMoney(number, c, d, t) {
var n = number,
c = isNaN(c = Math.abs(c)) ? 2 : c,
d = d == undefined ? "." : d,
t = t == undefined ? "," : t,
s = n < 0 ? "-" : "",
i = String(parseInt(n = Math.abs(Number(n) || 0).toFixed(c))),
j = (j = i.length) > 3 ? j % 3 : 0;
return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
};
function calculateCost()
{
var cost = downpayment + ( monthly * ( Math.pow( 1 + ( interest / 12 ), term * 12 ) - 1 ) / ( ( interest / 12 ) * ( Math.pow( 1 + ( interest / 12 ), term * 12 ) ) ) );
cost = "$" + formatMoney(cost, 2, ".", ",")
return cost;
}
但是它吐出的答案太大了,不合逻辑。熟悉JS的人可以找出我要去哪里,将公式转换为JS吗?