Excel ROUND function in Javascript

I've got a mathematical formula in Excel, which is the following:

ROUND((B2+C2)*(B55/100)/12;2)

Initial values:

  • B2 = 1000
  • C2 = 0
  • B55 = 0,03

Results (t means time in months). 

Here is my Javascript approach:

(function _calculateRates() {
  var singlePayment = parseInt(1000, 10),
    amount = singlePayment,
    monthlyPayment = parseInt(0, 10),
    investTime = parseFloat(12),
    rate_a = parseFloat(0.03),
    rate_b = parseFloat(0.03),
    investment = monthlyPayment,
    interest = 0;

for (var month = 0; month < investTime; month += 1) {
investment = (month === 0) ? 0 : monthlyPayment;

interest = Number(((amount + investment) * (rate_a / 100) / 12).toFixed(2));
amount = Number((amount + interest + investment).toFixed(2));

}
console.log('Result: ', amount);
})();


As one can see, the result is not correct.

Where can I find the Microsoft Excel algorithm for ROUND() ?

#javascript #excel #algorithm

3 Likes15.50 GEEK