Net Asset Value Calculation

function calculateNAV() { var assets = document.getElementById("totalAssets").value; var liabilities = document.getElementById("totalLiabilities").value; var shares = document.getElementById("sharesOutstanding").value; var resultDisplay = document.getElementById("navDisplay"); var resultContainer = document.getElementById("navResultContainer"); var errorDisplay = document.getElementById("errorDisplay"); // Reset displays errorDisplay.style.display = "none"; resultContainer.style.display = "none"; // Validation if (!assets || assets < 0) { showError("Please enter a valid amount for Total Assets."); return; } if (!liabilities || liabilities < 0) { showError("Please enter a valid amount for Total Liabilities."); return; } if (!shares || shares <= 0) { showError("Number of Shares Outstanding must be greater than zero."); return; } var totalAssets = parseFloat(assets); var totalLiabilities = parseFloat(liabilities); var totalShares = parseFloat(shares); var netAssets = totalAssets – totalLiabilities; var nav = netAssets / totalShares; // Output formatting resultDisplay.innerHTML = "$" + nav.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 4}); resultContainer.style.display = "block"; } function showError(message) { var errorDisplay = document.getElementById("errorDisplay"); errorDisplay.innerHTML = message; errorDisplay.style.display = "block"; }

Leave a Comment