EMI Calculator for Personal Loan

by sunil puvvada

JavaScript

function calculateEMI(principal, interestRate, tenure) {
  // Convert interest rate to monthly decimal
  interestRate = interestRate / 100 / 12;

  // Convert tenure to months
  tenure = tenure * 12;

  // Calculate EMI
  var emi =
    (principal * interestRate * Math.pow(1 + interestRate, tenure)) /
    (Math.pow(1 + interestRate, tenure) - 1);

  return emi.toFixed(2);
}

// Example usage
var loanPrincipal = 100000; // Loan principal amount
var loanInterestRate = 12; // Annual interest rate
var loanTenure = 5; // Loan tenure in years

var emi = calculateEMI(loanPrincipal, loanInterestRate, loanTenure);
var totalAmount = emi * loanTenure;
var totalInterest = totalAmount - loanPrincipal;
console.log("EMI: ", emi);
console.log("totalAmount ", totalAmount);
console.log("totalInterest ", totalInterest);