2016-07-26 10 views
1

Dies wird die Excel-Formel, die ich habeExcel-Formel JavaScript-Funktion

fx = ROUNDUP(C17/((1-(1/(1+(C19/12))^(C18*12)))/(C19/12)),0) 

excel formula

Dies ist das Ergebnis sollte sein: the result

Dies ist die JavaScript-Funktion, die ich schrieb:

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(); 

} 

Bei t er Moment das Ergebnis, dass ich von der Excel-Formel und der Javascript-Funktion bekomme, ist nicht das Gleiche. Jede Hilfe würde sehr geschätzt werden.

+1

Könnten Sie auch hinzufügen, die Excel-Formel im Klar Text, zum Kopieren/Formatieren? – boxmein

Antwort

0

In JS würde die äquivalente Berechnung dieses:

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);

Der Hauptunterschied ist die Multiplikation der Zinssatz (* 1200 zu * 12 gegen) als Excel speichert Werte Prozentsatz als Floating Punkte zwischen 0 und 1.

Wenn Sie in der gleichen Weise wie Excel berechnen würde es vorziehen, dann müssen Sie die Eingabegeschwindigkeit in diese konvertieren:

var C17 = 10000; 
 
var C18 = 5; 
 
var C19 = 0.0444; // Note the difference here 
 

 
var interest = C19/12; // and here 
 
var foo = Math.ceil(C17 * interest/(1 - (Math.pow(1/(1 + interest), C18 * 12)))); 
 

 
console.log(foo);

+0

Vielen Dank. das funktioniert perfekt. Das gleiche Ergebnis wie das Excel erhalten. –