Blog Details

Maths Function


                                
                                    <h2>* Math Object :-</h2>
<ul>
	<li>The Math object allows you to <strong>perform mathematical tasks.</strong></li>
	<li>The Math object includes several<strong> mathematical constants</strong> and <strong>methods. </strong></li>
</ul>
&nbsp;
<h3><b> Syntax </b></h3>
var x=Math.PI;
var y=Math.sqrt(16);

&nbsp;
<h3><b>Note:</b></h3>
Math is <strong>not</strong> a <strong>constructor</strong>. All<strong> properties and methods</strong> of Math can be <strong>called</strong> by using Math as an object <strong>without creating it.</strong>

&nbsp;
<h2>Mathematical Constants :-</h2>
<div>
<ul>
	<li>Math.E</li>
	<li>Math.PI</li>
	<li>Math.SQRT2</li>
	<li>Math.SQRT1_2</li>
	<li>Math.LN2</li>
	<li>Math.LN10</li>
	<li>Math.LOG2E</li>
	<li>Math.LOG10E</li>
</ul>
</div>
<div></div>
<div>
<h2>Mathematical Methods :-</h2>
<h3><strong>1)  round() :-</strong></h3>
<ul>
	<li>The following example uses the round() method of the Math object to round a number to the nearest integer:</li>
</ul>
<strong>Example :</strong>
<ul>
	<li>document.write(Math.round(4.7));</li>
</ul>
<strong>Output :</strong>

5

&nbsp;
<h3>2) random() :-</h3>
<ul>
	<li>The following example uses the random() method of the Math object to return a random number between 0 and 1:</li>
</ul>
<strong>Example :</strong>
<ul>
	<li>document.write(Math.random());</li>
</ul>
<strong>Output :</strong>

0.40111692785285413

&nbsp;
<h3>3) floor() :-</h3>
<ul>
	<li>The following example uses the floor() and random() methods of the Math object to return a random number between 0 and 10:</li>
</ul>
<strong>Example :</strong>
<ul>
	<li>document.write(Math.floor(Math.random()*11));</li>
</ul>
<strong>Output :</strong>

5

</div>
                                    


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