This calculator helps you determine the rate of growth between two points in time. This is a fundamental concept in many fields, including biology, economics, finance, and physics, to understand how a quantity changes over a period. The rate of growth is typically expressed as a percentage per unit of time.
function calculateGrowthRate() {
var initialValue = parseFloat(document.getElementById("initialValue").value);
var finalValue = parseFloat(document.getElementById("finalValue").value);
var timePeriod = parseFloat(document.getElementById("timePeriod").value);
var resultDiv = document.getElementById("result");
if (isNaN(initialValue) || isNaN(finalValue) || isNaN(timePeriod) || timePeriod 0) {
growthRate = Infinity; // Infinite growth from zero to a positive number
} else if (initialValue > 0 && finalValue === 0) {
growthRate = -100 / timePeriod; // 100% decrease over the period if it reached zero
}
resultDiv.innerHTML = "The rate of growth is: " + growthRate.toFixed(2) + "% per time unit.";
}
#growthRateCalculator {
font-family: sans-serif;
padding: 20px;
border: 1px solid #ccc;
border-radius: 8px;
max-width: 400px;
margin: 20px auto;
box-shadow: 2px 2px 10px rgba(0,0,0,0.1);
}
.input-section {
margin-bottom: 15px;
}
.input-section label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
.input-section input {
width: calc(100% – 22px);
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
}
button {
padding: 10px 15px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}
button:hover {
background-color: #0056b3;
}
#result {
margin-top: 20px;
font-weight: bold;
color: #333;
}