**JavaScript Math Object**

Math object is an object that has many methods and properties to manipulate numbers and also math functions. All method or property that is used we must begin with the word Math, for example, is as follows:

Math.cos (1);

**Here is a table of standard methods of math object:****abs ()**returns the absolute value of number, if positive numbers he would send back the numbers, otherwise if negative numbers, he would send a positive

x = Math.abs (3.17);

/ / Result is x = 3:17

x = Math.abs (-3.17);

/ / Result is x = 3:17

**ceil ()**returns the smallest integer greater equal to the value of the parameters given

x = Math.ceil (6:01);

/ / Result is x = 7

x = Math.ceil (3.99);

/ / Result is x = 4

**floor ()**returns the greatest integer value less equal to the value of the parameters given

x = Math.floor (6:01);

/ / Result is x = 6

x = Math.floor (3.99);

/ / Result is x = 3

**round ()**round off numbers in a parameter to the nearest integer, if the number is 0.5 then it will be rounded upwards

x = Math.round (6:01);

/ / Result is x = 6

x = Math.round (3.80);

/ / Result is x = 4

x = Math.round (3:50);

/ / Result is x = 4

**max (num1, num2)**returns the largest value between the two parameters compared

var x = Math.max (6,7.25);

/ / Result is x = 7:25

var x = Math.max (-8.21, -3.65);

/ / Result is x = -3.65

**min (num1, num2)**returns the smallest value between the two parameters compared

x = Math.min (6,7.25);

/ / Result is x = 6

x = Math.min (-8.21, -3.65);

/ / Result is x = -8.21

**pow (num1, num2)**returns the value of the num1 rank num2

x = Math.pow (3.3);

/ / Result is x = 27

x = Math.pow (9,0.5);

/ / Result is x = 3

**random ()**Returns a random value between 0 to 1, the value generated by the system clock of the computer

x = Math.random ();

/ / Result is x = 0.6489534931546957

**sqrt (num)**Returns the root of the number that is passed as a parameter

x = Math.sqrt (9);

/ / Result is x = 3

## 0 comments:

## Post a Comment