Sometimes, we want to make a number a percentage with JavaScript.
In this article, we’ll look at how to make a number a percentage with JavaScript.
How to make a number a percentage with JavaScript?
To make a number a percentage with JavaScript, we can get the quotient of 2 numbers and multiply that by 100.
For instance, we write
const number1 = 4.98;
const number2 = 5.98;
console.log(Math.floor((number1 / number2) * 100));
to divide number1
by number2
and multiply the quotient by 100.
Then we call Math.floor
on the product to get the floor of it.
Conclusion
To make a number a percentage with JavaScript, we can get the quotient of 2 numbers and multiply that by 100.