Calculate a percentage of a given number or find what percentage one number is of another.
Or, leave Percentage blank to find what percentage 'Number' is of 'Another Number'.
Result
—
Understanding How to Calculate Percentages
Percentages are a way to express a part of a whole as a fraction of 100. The word "percent" itself means "per hundred". Understanding how to calculate percentages is a fundamental skill with applications in finance, statistics, everyday shopping, and much more.
Calculating a Percentage of a Number
To find what a specific percentage is of a given number, you can use the following formula:
Result = (Percentage / 100) * Number
For example, if you want to find 15% of 200:
Result = (15 / 100) * 200 = 0.15 * 200 = 30
This means 15% of 200 is 30. This is useful for calculating discounts, taxes, or commissions.
Calculating What Percentage One Number Is of Another
Sometimes, you need to determine what percentage a smaller number (or a part) is in relation to a larger number (or a whole). The formula for this is:
Percentage = (Part / Whole) * 100
In our calculator, if you provide 'The Number' and 'Another Number', and leave 'The Percentage' blank, 'The Number' is treated as the 'Part' and 'Another Number' is treated as the 'Whole' (or base) to find the percentage.
For example, if you want to know what percentage 50 is of 200:
Percentage = (50 / 200) * 100 = 0.25 * 100 = 25%
This means 50 is 25% of 200. This is commonly used to understand performance, growth rates, or the proportion of a component within a total.
How the Calculator Works
This calculator takes your input values: 'The Number' (the base value), 'The Percentage' (the percentage you want to find or apply), and optionally 'Another Number' (used as the base when finding what percentage 'The Number' is of it).
If you enter values for 'The Number' and 'The Percentage', it calculates (Percentage / 100) * Number.
If you enter values for 'The Number' and 'Another Number', but leave 'The Percentage' blank, it calculates (Number / Another Number) * 100.
It handles invalid inputs and provides clear results.
function calculatePercentage() {
var numberValueInput = document.getElementById("numberValue");
var percentageValueInput = document.getElementById("percentageValue");
var anotherNumberValueInput = document.getElementById("anotherNumberValue");
var numberValue = parseFloat(numberValueInput.value);
var percentageValue = parseFloat(percentageValueInput.value);
var anotherNumberValue = parseFloat(anotherNumberValueInput.value);
var resultValueElement = document.getElementById("result-value");
var resultDescriptionElement = document.getElementById("result-description");
var result = NaN;
var description = "";
if (!isNaN(numberValue) && !isNaN(percentageValue)) {
// Case 1: Calculate a percentage OF a number
result = (percentageValue / 100) * numberValue;
description = "is " + percentageValue + "% of " + numberValue;
resultValueElement.textContent = result.toFixed(2); // Display with 2 decimal places
resultDescriptionElement.textContent = result.toFixed(2) + " " + description;
} else if (!isNaN(numberValue) && !isNaN(anotherNumberValue) && isNaN(percentageValue)) {
// Case 2: Find what percentage 'numberValue' is of 'anotherNumberValue'
if (anotherNumberValue === 0) {
resultValueElement.textContent = "Error";
resultDescriptionElement.textContent = "Cannot divide by zero.";
return;
}
result = (numberValue / anotherNumberValue) * 100;
description = "is what percentage of " + anotherNumberValue;
resultValueElement.textContent = result.toFixed(2) + "%"; // Display with '%' sign
resultDescriptionElement.textContent = numberValue + " " + description;
} else {
// Invalid input combination
resultValueElement.textContent = "Invalid Input";
resultDescriptionElement.textContent = "Please enter valid numbers for calculation.";
}
}