# Math Methods

The Math object methods enable us to perform tasks on one or more numbers. 1. abs() The JavaScript's Math abs() method returns the absolute value of a number. An absolute value is the positive value of a number be it positive or negative. This means when a negative value is passed to the method, it returns its positive equivalent.
``````<script>
document.write(Math.abs(-315)); //returns 315
</script>``````
2. acos() Returns in radians, the arccosine of a number.
``````<script>
document.write(Math.acos(1));
</script>``````
3. asin() Returns in radians, the arcsine of a number.
``````<script>
document.write(Math.asin(1));
</script>``````
4. atan() Returns in radians, the arctangent of a number.
``````<script>
document.write(Math.atan(1));
</script>``````
5. ceil() Rounds a value up to its nearest integer. This means once a value have a decimal point and any value other than zero (0) e.g 3.01, it rounds it to 4.
``````<script>
document.write(Math.ceil(3.4) + Math.ceil(1.5) + Math.ceil(2.8)); //returns 4+2+3 = 9
</script>``````
6. cos() Returns the cosine of a number.
``````<script>
document.write(Math.cos(1));
</script>``````
7. exp() Raises the Euler's number(2.718281828459045) to the power of the number specified in its parameter.
``````<script>
document.write(Math.exp(10)); //Raises Euler's number to the power of 10
</script>``````
8. floor() Rounds a value down to its nearest integer. This means it takes off the decimal part of a number.
``````<script>
document.write(Math.floor(3.4) + Math.floor(1.5) + Math.floor(2.8)); //returns 3+1+2 = 6
</script>``````
9. log() Returns the natural logarithm (base E) of any number.
``````<script>
document.write(Math.log(10));
</script>``````
10. max() Returns the highest value among a list of numbers assigned to its parameters.
``````<script>
document.write("The highest value is "+Math.max(1, 10, 3, 15, 21, 5));
</script>``````
11. min() Returns the lowest value among a list of numbers assigned to its parameters.
``````<script>
document.write("The lowest value is "+Math.min(1, 10, 3, 15, 21, 5));
</script>``````
12. pow() Raises a number to the power of another. It's first argument is the number to be raised to the power of the second argument e.g pow(5, 2) will raise 5 to the power of 2.
``````<script>
alert(Math.pow(3,2)); //raises 3 to the power of 2
</script>``````
13. random() Returns a random number from 0 to 1. It may return 0 or just any decimal number lying between 0 to 1 e.g 0.45 but not 1.
``````<script>
document.write(Math.random());
</script>``````
To get a random number base on your own specifications e.g a random number from 0 to 10 but 10 not inclusive. You simply multiply 10 with the random() method.
``````<script>
document.write(Math.random() * 10); //random number from 0 to 10 but not 10
</script>``````
What happens then is whatever random number is gotten from 0 to 1 is multiply by the specified number (10) to get another value. To get a non - decimal value, you can thereafter floor() the random number generated.
``````<script>
document.write(Math.floor(Math.random() * 100)); //non - decimal random number from 0 to 100
</script>``````
To specify a minimum value to start randomizing from, you may want to define a custom function as shown below,
``````<script>
function randomFrom(start, end){
var randomNum = (Math.random() * (start - end)) + end;

return randomNum;
}

document.write(Math.floor(randomFrom(3, 6))); //returns the random number from 3 to 6
</script>``````
14. round() This method rounds a number to it nearest integer. To do this, it pays attention to the digit after the decimal point. If the digit is 5 or greater than 5, it adds 1 to the number before the decimal point else it adds nothing.
``````<script>
document.write("You get "+Math.round(4.15)+" when you round 4.15.<br/><br/>You get "+Math.round(4.5)+" when you round 4.5.");
</script>``````
15. sin() This method returns the sine of a number.
``````<script>
document.write(Math.sin(1));
</script>``````
16. sqrt() Returns the square root of a number.
``````<script>
document.write(Math.sqrt(25)); //square root of 25
</script>``````
17. tan() Returns the tangent of a number.
``````<script>
document.write(Math.tan(5));
</script>``````
SUMMARY
1. In this page, we listed the various methods of the Math object.
2. They allow you to manipulate numbers. For example, instead of having to devise and define a function that will help you get the square root of any number, you can make use of the sqrt() method of the Math object.
3. There are other numerous methods.
4. Remember you don't need to create an object of the Math to start using its methods. It is already a literal object and not a prototype.
Take a short quiz on Math Methods.
Ask a question or tell us if Math Methods is easy or not.
cent?