Net Present Value (NPV) Calculator
The Net Present Value (NPV) is a crucial metric used in capital budgeting and investment appraisal to determine the profitability of a projected investment or project. It calculates the difference between the present value of cash inflows and the present value of cash outflows over a period of time. A positive NPV indicates that the projected earnings generated by a project or investment will be greater than the anticipated costs. Essentially, NPV helps you understand how much value an investment is expected to add to your company.
function calculateNPV() {
var initialInvestment = parseFloat(document.getElementById("initialInvestment").value);
var discountRate = parseFloat(document.getElementById("discountRate").value) / 100; // Convert percentage to decimal
var cashFlowsInput = document.getElementById("cashFlows").value;
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = ""; // Clear previous results
if (isNaN(initialInvestment) || isNaN(discountRate) || cashFlowsInput === "") {
resultDiv.innerHTML = "Please enter valid numbers for all fields.";
return;
}
var cashFlowsArray = cashFlowsInput.split(',').map(function(item) {
return parseFloat(item.trim());
});
var npv = -initialInvestment; // Start with the initial investment as a negative cash flow
for (var i = 0; i < cashFlowsArray.length; i++) {
var cashFlow = cashFlowsArray[i];
if (isNaN(cashFlow)) {
resultDiv.innerHTML = "Please ensure all cash flows are valid numbers.";
return;
}
npv += cashFlow / Math.pow((1 + discountRate), (i + 1));
}
resultDiv.innerHTML = "
Result
The Net Present Value (NPV) is:
" + npv.toFixed(2) + "";
if (npv > 0) {
resultDiv.innerHTML += "Interpretation: The investment is expected to be profitable as the NPV is positive.";
} else if (npv < 0) {
resultDiv.innerHTML += "Interpretation: The investment is expected to be unprofitable as the NPV is negative.";
} else {
resultDiv.innerHTML += "Interpretation: The investment is expected to break even as the NPV is zero.";
}
}
.calculator-container {
font-family: sans-serif;
border: 1px solid #ccc;
padding: 20px;
border-radius: 8px;
max-width: 600px;
margin: 20px auto;
background-color: #f9f9f9;
}
.calculator-container h2 {
text-align: center;
margin-bottom: 20px;
color: #333;
}
.calculator-form {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 15px;
margin-bottom: 20px;
}
.form-group {
display: flex;
flex-direction: column;
}
.form-group label {
margin-bottom: 5px;
font-weight: bold;
color: #555;
}
.form-group input[type="number"],
.form-group input[type="text"] {
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
width: 100%;
box-sizing: border-box;
}
.calculator-form button {
grid-column: 1 / -1;
padding: 12px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s ease;
}
.calculator-form button:hover {
background-color: #0056b3;
}
.calculator-result {
margin-top: 20px;
padding: 15px;
border: 1px dashed #007bff;
border-radius: 4px;
background-color: #e7f3ff;
text-align: center;
}
.calculator-result h3 {
margin-top: 0;
color: #0056b3;
}
.calculator-result strong {
color: #007bff;
}