[Edit]
+
0
-
0

js calculate percentage between two numbers

1 2 3 4 5 6 7 8 9 10 11 12 13 14
const x = 30; const y = 40; const result = (x / y) * 100; console.log(result + '%'); // Output: 75% (so x is 75% of y) // More examples: console.log((30 / 60) * 100 + '%'); // Output: 50% (30 is 50% of 60) console.log((10 / 50) * 100 + '%'); // Output: 20% (10 is 20% of 50) console.log((15 / 10) * 100 + '%'); // Output: 150% (15 is 150% of 10) console.log((60 / 30) * 100 + '%'); // Output: 200% (60 is 200% of 30)