excel公式到javascript函数
这是我拥有的优秀公式
fx = ROUNDUP(C17/((1-(1/(1+(C19/12))^(C18*12)))/(C19/12)),0)
这是结果应该是:
这是我写的javascript函数:
function refreshRenoLoanCalculator() { var amt = parseInt($('.calc-renoloan .principal-amount').val().replace(/,/g, ''), 10) console.log(amt); //10 000 var rate = $('.calc-renoloan .loan-rate').val(); console.log(rate); //0.0444 var tenure = $('.calc-renoloan .loan-tenure').val(); console.log(tenure); // 5 var a = rate / 100. / 12.; console.log(a); var b = 1. + a; b = Math.pow(b, (tenure * 12)) - 1.; console.log(b); var FC = a / b + a; FC = FC.toFixed(10); console.log(FC); var RP = amt * FC; console.log(RP); toolsSetCalculatedValue('.calc-renoloan .calc-result-installment', Math.ceil(RP).toLocaleString().split('.')[0]) $('.calc-renoloan .results-container').slideDown(); }
目前我从Excel公式和javascript函数得到的结果是不一样的。 任何帮助将不胜感激。
在JS中,等价的计算是这样的:
var C17 = 10000; var C18 = 5; var C19 = 4.44; var interest = C19 / 1200; var foo = Math.ceil(C17 * interest / (1 - (Math.pow(1/(1 + interest), C18 * 12)))); console.log(foo);