Calculate Simple Interest in JavaScript
P*R*T / 100. Rate 5 means 5%, not 0.05.
BeginnerBasic ProgramsExample 9 of 10
calculate-simple-interest.js
1// Formula: SI = (P × R × T) / 1002// Where: P = Principal, R = Rate, T = Time34let principal = 10000;5let rate = 5; // 5% per annum6let time = 2; // 2 years78let simpleInterest = (principal * rate * time) / 100;9let amount = principal + simpleInterest;1011console.log("Principal: ₹" + principal);12console.log("Rate: " + rate + "% per annum");13console.log("Time: " + time + " years");14console.log("Simple Interest: ₹" + simpleInterest);15console.log("Total Amount: ₹" + amount);1617// Function version18function calculateSimpleInterest(p, r, t) {19 let interest = (p * r * t) / 100;20 let total = p + interest;21 return {22 principal: p,23 rate: r,24 time: t,25 interest: interest,26 totalAmount: total27 };28}2930let result = calculateSimpleInterest(5000, 8, 3);31console.log("\nUsing function:");32console.log(`Principal: ₹${result.principal}`);33console.log(`Interest: ₹${result.interest.toFixed(2)}`);34console.log(`Total: ₹${result.totalAmount.toFixed(2)}`);
Output
Principal: ₹10000 Rate: 5% per annum Time: 2 years Simple Interest: ₹1000 Total Amount: ₹11000 Using function: Principal: ₹5000 Interest: ₹1200.00 Total: ₹6200.00
What's going on
Enter 5 for 5%. Enter 0.05 and you undercharge by 100×.
1000 at 5% for 2 years is 100. If you do not get 100, you treated 5 as 0.05.