How to calculate percentage between two numbers in Node.js

1 Answer

0 votes
function GetPercentage(num1, num2) {
    return (num1 / num2) * 100;
}
 
console.log("25 is " + GetPercentage(25, 100) + "% of 100");
 
console.log("100 is " + GetPercentage(100, 25) + "% of 25");
 
console.log("20 is " + GetPercentage(20, 57) + "% of 57");
console.log("20 is " + GetPercentage(20, 57).toFixed(2) + "% of 57");   
    
    
    
    
    
/*
run:
  
25 is 25% of 100
100 is 400% of 25
20 is 35.08771929824561% of 57
20 is 35.09% of 57
 
*/

 



answered May 20, 2022 by avibootz
edited May 20, 2022 by avibootz

Related questions

1 answer 166 views
2 answers 188 views
1 answer 132 views
1 answer 143 views
1 answer 236 views
...