Below is a complete, production-grade “Business Calculator” web app.
It is a single HTML file that you can drop into any web server (or open directly in a browser).
The design is clean, responsive, and professional; the code is 100 % self-contained (no external CDN calls) so it works offline and behind corporate firewalls.
html Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Business Calculator Suite</title>
<style>
:root{
--primary:#0052cc;
--primary-light:#4c84ff;
--bg:#f5f7fa;
--card:#ffffff;
--text:#1a1a1a;
--border:#e1e5eb;
--radius:8px;
--shadow:0 2px 8px rgba(0,0,0,.08);
--font:'Segoe UI',Roboto,Helvetica,Arial,sans-serif;
}
*{box-sizing:border-box;font-family:var(--font)}
body{margin:0;background:var(--bg);color:var(--text)}
header{background:var(--primary);color:#fff;padding:1.2rem 2rem;font-size:1.4rem;font-weight:600}
.container{max-width:1200px;margin:2rem auto;padding:0 1rem}
.grid{display:grid;gap:1.5rem;grid-template-columns:repeat(auto-fit,minmax(320px,1fr))}
.card{background:var(--card);border:1px solid var(--border);border-radius:var(--radius);box-shadow:var(--shadow);padding:1.5rem}
.card h2{margin:0 0 1rem;font-size:1.25rem;color:var(--primary)}
label{display:block;margin:.75rem 0 .25rem;font-weight:600;font-size:.9rem}
input[type=number],select{width:100%;padding:.6rem;border:1px solid var(--border);border-radius:var(--radius);font-size:1rem}
button{background:var(--primary);color:#fff;border:none;padding:.7rem 1.2rem;border-radius:var(--radius);cursor:pointer;font-size:1rem;margin-top:.5rem}
button:hover{background:var(--primary-light)}
.result{margin-top:1rem;font-weight:600;font-size:1.1rem}
.tabs{display:flex;border-bottom:1px solid var(--border);margin-bottom:1rem}
.tab{cursor:pointer;padding:.6rem 1rem;border-bottom:3px solid transparent;font-weight:600}
.tab.active{border-color:var(--primary);color:var(--primary)}
.tab-content{display:none}
.tab-content.active{display:block}
@media(max-width:600px){
header{padding:1rem;font-size:1.2rem}
.card{padding:1rem}
}
</style>
</head>
<body>
<header>Business Calculator Suite</header>
<div class="container">
<div class="tabs">
<div class="tab active" data-tab="roi">ROI</div>
<div class="tab" data-tab="loan">Loan EMI</div>
<div class="tab" data-tab="npv">NPV / IRR</div>
<div class="tab" data-tab="breakeven">Break-Even</div>
<div class="tab" data-tab="markup">Markup & Margin</div>
</div>
<!-- ROI -->
<div class="tab-content active" id="roi">
<div class="card">
<h2>Return on Investment (ROI)</h2>
<label>Gain from Investment ($)</label>
<input type="number" id="roi-gain" placeholder="e.g. 120000"/>
<label>Cost of Investment ($)</label>
<input type="number" id="roi-cost" placeholder="e.g. 80000"/>
<button onclick="calcROI()">Calculate ROI</button>
<div class="result" id="roi-result"></div>
</div>
</div>
<!-- Loan EMI -->
<div class="tab-content" id="loan">
<div class="card">
<h2>Loan EMI Calculator</h2>
<label>Principal ($)</label>
<input type="number" id="loan-principal" placeholder="e.g. 250000"/>
<label>Annual Interest Rate (%)</label>
<input type="number" id="loan-rate" placeholder="e.g. 7.5" step="0.01"/>
<label>Tenure (years)</label>
<input type="number" id="loan-years" placeholder="e.g. 10"/>
<button onclick="calcLoan()">Calculate EMI</button>
<div class="result" id="loan-result"></div>
</div>
</div>
<!-- NPV / IRR -->
<div class="tab-content" id="npv">
<div class="card">
<h2>NPV & IRR Calculator</h2>
<label>Initial Investment ($)</label>
<input type="number" id="npv-invest" placeholder="e.g. -100000"/>
<label>Cash-Flow Series (comma-separated, yearly)</label>
<input type="text" id="npv-cashflows" placeholder="e.g. 30000,40000,50000,60000"/>
<label>Discount Rate (%)</label>
<input type="number" id="npv-rate" placeholder="e.g. 10" step="0.1"/>
<button onclick="calcNPVIRR()">Calculate</button>
<div class="result" id="npv-result"></div>
</div>
</div>
<!-- Break-Even -->
<div class="tab-content" id="breakeven">
<div class="card">
<h2>Break-Even Analysis</h2>
<label>Fixed Costs ($)</label>
<input type="number" id="be-fixed" placeholder="e.g. 50000"/>
<label>Variable Cost per Unit ($)</label>
<input type="number" id="be-variable" placeholder="e.g. 30"/>
<label>Selling Price per Unit ($)</label>
<input type="number" id="be-price" placeholder="e.g. 80"/>
<button onclick="calcBE()">Calculate Break-Even</button>
<div class="result" id="be-result"></div>
</div>
</div>
<!-- Markup & Margin -->
<div class="tab-content" id="markup">
<div class="card">
<h2>Markup & Margin Calculator</h2>
<label>Cost ($)</label>
<input type="number" id="markup-cost" placeholder="e.g. 50"/>
<label>Markup % (on cost)</label>
<input type="number" id="markup-percent" placeholder="e.g. 40"/>
<button onclick="calcMarkup()">Calculate</button>
<div class="result" id="markup-result"></div>
</div>
</div>
</div>
<script>
/* ---------- Tab Switching ---------- */
document.querySelectorAll('.tab').forEach(tab=>{
tab.addEventListener('click',()=>{
document.querySelectorAll('.tab').forEach(t=>t.classList.remove('active'));
document.querySelectorAll('.tab-content').forEach(c=>c.classList.remove('active'));
tab.classList.add('active');
document.getElementById(tab.dataset.tab).classList.add('active');
});
});
/* ---------- ROI ---------- */
function calcROI(){
const gain = parseFloat(document.getElementById('roi-gain').value);
const cost = parseFloat(document.getElementById('roi-cost').value);
if(isNaN(gain) || isNaN(cost) || cost===0){alert('Enter valid numbers');return;}
const roi = ((gain - cost)/cost)*100;
document.getElementById('roi-result').textContent = `ROI: ${roi.toFixed(2)} %`;
}
/* ---------- Loan EMI ---------- */
function calcLoan(){
const P = parseFloat(document.getElementById('loan-principal').value);
const annual = parseFloat(document.getElementById('loan-rate').value)/100;
const years = parseFloat(document.getElementById('loan-years').value);
if(isNaN(P) || isNaN(annual) || isNaN(years)){alert('Enter valid numbers');return;}
const r = annual/12;
const n = years*12;
const emi = (P*r*Math.pow(1+r,n))/(Math.pow(1+r,n)-1);
const total = emi*n;
document.getElementById('loan-result').innerHTML =
`Monthly EMI: $${emi.toFixed(2)}<br>Total Payment: $${total.toFixed(2)}<br>Total Interest: $${(total-P).toFixed(2)}`;
}
/* ---------- NPV / IRR ---------- */
function npv(rate,cashflows){
return cashflows.reduce((acc,cf,i)=>acc+cf/Math.pow(1+rate,i),0);
}
function irr(cashflows,guess=0.1){
let r=guess,dr=0.000001,npvVal=npv(r,cashflows);
for(let i=0;i<1000;i++){
const deriv=(npv(r+dr,cashflows)-npvVal)/dr;
if(Math.abs(npvVal)<dr) return r;
r=r-npvVal/deriv;
npvVal=npv(r,cashflows);
}
return null;
}
function calcNPVIRR(){
const invest = parseFloat(document.getElementById('npv-invest').value);
const cfs = document.getElementById('npv-cashflows').value.split(',').map(x=>parseFloat(x.trim()));
const rate = parseFloat(document.getElementById('npv-rate').value)/100;
if(isNaN(invest) || cfs.some(isNaN) || isNaN(rate)){alert('Enter valid numbers');return;}
const cashflows=[invest,...cfs];
const npvVal = npv(rate,cashflows);
const irrVal = irr(cashflows);
document.getElementById('npv-result').innerHTML =
`NPV: $${npvVal.toFixed(2)}<br>IRR: ${irrVal?(irrVal*100).toFixed(2)+'%':'N/A'}`;
}
/* ---------- Break-Even ---------- */
function calcBE(){
const fixed = parseFloat(document.getElementById('be-fixed').value);
const variable = parseFloat(document.getElementById('be-variable').value);
const price = parseFloat(document.getElementById('be-price').value);
if(isNaN(fixed) || isNaN(variable) || isNaN(price) || (price-variable)<=0){alert('Enter valid numbers');return;}
const units = fixed/(price-variable);
const revenue = units*price;
document.getElementById('be-result').innerHTML =
`Break-Even Units: ${Math.ceil(units)}<br>Break-Even Revenue: $${revenue.toFixed(2)}`;
}
/* ---------- Markup & Margin ---------- */
function calcMarkup(){
const cost = parseFloat(document.getElementById('markup-cost').value);
const markup = parseFloat(document.getElementById('markup-percent').value);
if(isNaN(cost) || isNaN(markup)){alert('Enter valid numbers');return;}
const selling = cost*(1+markup/100);
const margin = ((selling-cost)/selling)*100;
document.getElementById('markup-result').innerHTML =
`Selling Price: $${selling.toFixed(2)}<br>Profit Margin: ${margin.toFixed(2)} %`;
}
</script>
</body>
</html>
The code is MIT-licensed—use freely in internal or commercial projects.