HTML code of Percentage Difference Calculator | Online Calculator
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
<title>Percentage Difference Calculator</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
max-width: 400px;
margin: 50px auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 5px;
background-color: #f9f9f9;
}
.form-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 5px;
}
input[type=”number”] {
width: 100%;
padding: 8px;
border: 1px solid #ccc;
border-radius: 3px;
}
button {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
border-radius: 3px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<div class=”container”>
<h2>Percentage Difference Calculator</h2>
<div class=”form-group”>
<label for=”initialValue”>Initial Value:</label>
<input type=”number” id=”initialValue” placeholder=”Enter initial value”>
</div>
<div class=”form-group”>
<label for=”finalValue”>Final Value:</label>
<input type=”number” id=”finalValue” placeholder=”Enter final value”>
</div>
<button onclick=”calculatePercentageDifference()”>Calculate</button>
<div class=”form-group”>
<label for=”percentageDifference”>Percentage Difference:</label>
<input type=”text” id=”percentageDifference” readonly>
</div>
</div>
<script>
function calculatePercentageDifference() {
var initialValue = parseFloat(document.getElementById(‘initialValue’).value);
var finalValue = parseFloat(document.getElementById(‘finalValue’).value);
var difference = finalValue – initialValue;
var percentageDifference = (difference / initialValue) * 100;
document.getElementById(‘percentageDifference’).value = percentageDifference.toFixed(2) + “%”;
}
</script>
</body>
</html>