Percentage calculations are one of those things that seem trivial until you're mid-task and your brain briefly refuses to produce the right formula. Is this "X percent of Y" or "X as a percent of Y"? What's the percentage change between these two numbers? How do I get back to the original value from a percentage increase? Developers encounter these questions regularly — in performance dashboards, log analysis, A/B testing, CSS layouts, and capacity planning. Having the formulas at hand and a tool to run them quickly removes the friction.
The Percentage Calculator on DevToolShack covers the most common calculation types in one place. Here are the scenarios where it earns its keep.
The Three Core Percentage Formulas
Most percentage problems reduce to one of three forms:
1. What is X% of Y?
result = (X / 100) * Y
// Example: What is 15% of 240?
(15 / 100) * 240 = 36
2. X is what percent of Y?
percent = (X / Y) * 100
// Example: 36 is what percent of 240?
(36 / 240) * 100 = 15%
3. Percentage change from X to Y
change = ((Y - X) / X) * 100
// Example: Response time went from 240ms to 180ms
((180 - 240) / 240) * 100 = -25% (a 25% improvement)
Real-World Developer Scenarios
Disk and memory usage
Your server has 512GB of disk. The monitoring alert fires at 80% used. How much space is that in GB, and how much remains? "What is 80% of 512?" gives 409.6GB used. The remaining 102.4GB is 20% of capacity. These are trivial to compute but easy to get backwards when you're debugging an incident at 2am — having a calculator at /tools/percentage-calculator/ ready to go is faster than mental arithmetic under pressure.
Error rates and SLOs
Your SLO allows 0.1% error rate. In a week with 2.4 million requests, how many errors is that? "What is 0.1% of 2,400,000?" gives 2,400 errors as your budget. If you had 1,850 errors, "1850 is what percent of 2400000?" gives 0.077%, which means you consumed about 77% of your error budget. Both forms of the calculation come up when writing SLO reports.
Performance improvements
Page load time dropped from 3.2 seconds to 2.1 seconds after an optimization. The percentage change formula gives ((2.1 - 3.2) / 3.2) × 100 = -34.4%. That's a 34.4% improvement — a meaningful number to include in a post-mortem or sprint review.
A/B test conversion rates
Variant A had 412 conversions from 8,200 visitors. Variant B had 389 from 7,950 visitors. Conversion rate A = (412 / 8200) × 100 = 5.02%. Conversion rate B = (389 / 7950) × 100 = 4.89%. The lift is ((5.02 - 4.89) / 4.89) × 100 = 2.66%. That percentage change calculation tells you how much better A performed relative to B, not just the absolute difference.
CSS percentage values
CSS percentages are relative to the parent element. If a container is 1200px wide and you want a child element that's 30% of that width, "What is 30% of 1200?" gives 360px. Going the other direction: you want a fixed 280px sidebar inside a 1200px container. "280 is what percent of 1200?" gives 23.3% — useful when you're switching from a fixed to a percentage-based layout. For more nuanced CSS unit conversions, the px to rem Converter handles the base-font-size math that percentages alone don't cover.
File size reduction from minification
Your CSS file was 48KB and is now 31KB after minification. "Percentage change from 48 to 31?" gives ((31 - 48) / 48) × 100 = -35.4%. The minifier reduced file size by 35.4%. This is a useful figure for justifying the build step or comparing minifiers. The post on minifying CSS and JavaScript covers what minifiers actually remove and what size reduction to expect.
Percentage Calculations in JavaScript
// What is X% of Y?
const percentOf = (x, y) => (x / 100) * y;
// X is what percent of Y?
const whatPercent = (x, y) => (x / y) * 100;
// Percentage change from a to b
const percentChange = (a, b) => ((b - a) / a) * 100;
// Round to 2 decimal places
const round2 = (n) => Math.round(n * 100) / 100;
console.log(round2(percentOf(15, 240))); // 36
console.log(round2(whatPercent(36, 240))); // 15
console.log(round2(percentChange(240, 180))); // -25
For situations where you need aspect ratio calculations alongside percentage work — such as determining what percentage of viewport width a particular element occupies at different breakpoints — the Ratio Calculator and the Percentage Calculator complement each other well.