Home > DeveloperSection > Beginner > Using Math Object in Java Script

Using Math Object in Java Script

JavaScript JavaScript 
0 Comment(s)
 3187  View(s)
Rate this:

Using Math Object in Java Script

We can take help of Math object to perform mathematical operation. Sometime we want to perform mathematical calculation on client side then we use concept of java script Math object. Java Script math object provides some built in function to perform mathematical task. In this demonstration we learn that how to use mathematical function in java script.

Some commonly used Math function in Java Script

Ø  Math.PI  :   Math.PI property gives value of PI.

Ø  Math.sqrt(<value>)  : Math.sqrt(<value>) method returns square root of number passed to its parameter.

Ø  Math.round(<double value>)   : Math.round(<double value>) returns an round of value of given decimal value. Such as round of value of 5.7 is 6.

Ø  Math.random()   :  Math.random() method return random number which is greater than 0 and less than 1.

Following function provides a demonstration to use Java Script Math object

<script type="text/javascript">

        function mathLibrary() {

            document.write("Value Of Pie is--->  : " + Math.PI + "<br />");

            document.write("Squareroot of 81 is---->  : " + Math.sqrt(81) + "<br />");

            document.write("Value of Sin 60 is---->  :  " + Math.sin(60) + "<br />");

            document.write("Round of 5.7 is --->   : " + Math.round(5.7) + "<br />");

            document.write("Random number generated by Java Script is---->  :" + Math.random() + "<br />");



Output of the following code snippet is as follows

Math Object in Java Script

Don't want to miss updates? Please click the below button!

Follow MindStick