module.exports = { slug: "simple-interest", title: "Simple interest", deck_category: "finance", description: "Computes simple (non-compounding) interest and the total amount owed or earned on a principal over a term.", inputs: [ { name: "principal", type: "number", unit: "currency units", required: true, description: "Starting amount", min: 0 }, { name: "annual_rate_percent", type: "number", unit: "%", required: true, description: "Simple annual interest rate", min: 0 }, { name: "years", type: "number", unit: "years", required: true, description: "Term of the loan or deposit", min: 0 } ], outputs: [ { name: "interest", unit: "currency units", description: "Total interest accrued over the term" }, { name: "total_amount", unit: "currency units", description: "Principal plus interest" } ], steps: [ "Convert the annual rate to a decimal: r = annual_rate_percent / 100.", "interest = principal * r * years.", "total_amount = principal + interest.", "Round both interest and total_amount to 2 decimals (money to cents)." ], constants: [], sources: [ { kind: "edition_page", value: "Brealey, Myers, Allen, Principles of Corporate Finance, 13th ed., Chapter 3 (The Time Value of Money), section on simple interest", title: "Principles of Corporate Finance", publisher: "McGraw-Hill", retrieved_utc: "2026-09-30T19:31:29Z", note: "Standard simple interest formula I = P*r*t" } ], disclaimer: null, questionText(inputs) { return `What is the simple interest and total amount owed on a principal of $${inputs.principal} at an annual rate of ${inputs.annual_rate_percent}% over ${inputs.years} years?`; }, run(inputs) { const { principal, annual_rate_percent, years } = inputs; if (typeof principal !== "number" || principal < 0) throw new Error("principal must be a non-negative number"); if (typeof annual_rate_percent !== "number" || annual_rate_percent < 0) throw new Error("annual_rate_percent must be a non-negative number"); if (typeof years !== "number" || years < 0) throw new Error("years must be a non-negative number"); const r = annual_rate_percent / 100; const interest = Math.round(principal * r * years * 100) / 100; const total_amount = Math.round((principal + interest) * 100) / 100; return { answer: `$${total_amount.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ",")}`, values: { interest, total_amount } }; }, examples: [ { name: "worked example", inputs: { principal: 1000, annual_rate_percent: 5, years: 3 }, expected: { answer: "$1,150.00" }, check: "hand computation: interest = 1000 * 0.05 * 3 = 150.00; total = 1000 + 150 = 1150.00" }, { name: "test vector: fractional year", inputs: { principal: 2500, annual_rate_percent: 4.5, years: 2.5 }, expected: { answer: "$2,781.25" }, check: "hand computation: interest = 2500 * 0.045 * 2.5 = 281.25; total = 2500 + 281.25 = 2781.25" } ] };