Blog Details

Maths Function



                                

* Math Object :-

  • The Math object allows you to perform mathematical tasks.
  • The Math object includes several mathematical constants and methods. 
 

 Syntax 

var x=Math.PI; var y=Math.sqrt(16);  

Note:

Math is not a constructor. All properties and methods of Math can be called by using Math as an object without creating it.  

Mathematical Constants :-

  • Math.E
  • Math.PI
  • Math.SQRT2
  • Math.SQRT1_2
  • Math.LN2
  • Math.LN10
  • Math.LOG2E
  • Math.LOG10E

Mathematical Methods :-

1)  round() :-

  • The following example uses the round() method of the Math object to round a number to the nearest integer:
Example :
  • document.write(Math.round(4.7));
Output : 5  

2) random() :-

  • The following example uses the random() method of the Math object to return a random number between 0 and 1:
Example :
  • document.write(Math.random());
Output : 0.40111692785285413  

3) floor() :-

  • The following example uses the floor() and random() methods of the Math object to return a random number between 0 and 10:
Example :
  • document.write(Math.floor(Math.random()*11));
Output : 5


Categories

Javascript

Latest posts

13.05.14
Implementing CRUD Operations ¶

<ul> <li>Now comes the fun part. We would like t

13.05.14
View

<ol> <li><a href="http://www.yiiframework.com/do

13.05.14
Creating Model

<ol> <li><a href="http://www.yiiframework.com/do

Get Free Quote