Hello Readers,
In today's we will learn about math object of JavaScript. We can use this object as it includes many mathematical methods and perform several tasks on numbers.
Lets have a look on the methods:
- random() : This method generates random number between 0 to 1 and the random number always smaller than 1.
Math.random();
- min() : This method used to find the lowest value.
Math.min(10, 2, -2, -200);
- max() : This method used to find highest value.
Math.max(10, 20, 500, 1);
- round() : This method used to find nearest integer value.
Math.round(5.8);
- floor() : This methods is used to find the largest integer equal or less than to the given number.
Math.floor(3.8);
- ceil() : This methods is used to find the smallest integer equal or greater than to the given number.
Math.ceil(4.4);
JavaScript provides 8 constants which are as follows:
Math.E // returns Euler's number
Math.PI // returns PI
Math.SQRT2 // returns the square root of 2
Math.SQRT1_2 // returns the square root of 1/2
Math.LN2 // returns the natural logarithm of 2
Math.LN10 // returns the natural logarithm of 10
Math.LOG2E // returns base 2 logarithm of E
Math.LOG10E // returns base 10 logarithm of E f
Hope this will help you :)
0 Comment(s)