JavaScript DHTML/Javascript Objects/Math

Материал из Web эксперт
Перейти к: навигация, поиск

"abs()" Example

   <source lang="html4strict">

   

<html> <body> <button onclick="alert(Math.abs(-10));">Math.abs(-10)</button> </body> </html>


 </source>
   
  


"acos()" Example

   <source lang="html4strict">

   

<html> <body> <button onclick="alert(Math.acos(1));">Math.acos(1)</button> </body> </html>


 </source>
   
  


"asin()" Example

   <source lang="html4strict">

   

<html> <body> <button onclick="alert(Math.asin(1));">Math.asin(1)</button> </body> </html>


 </source>
   
  


"atan2()" Example

   <source lang="html4strict">

   

<html> <body> <button onclick="alert(Math.atan2(1,1));">Math.atan2(1,1)</button> </body> </html>


 </source>
   
  


"atan()" Example

   <source lang="html4strict">

   

<html> <body> <button onclick="alert(Math.atan(1));">Math.atan(1)</button> </body> </html>


 </source>
   
  


"ceil()" Example

   <source lang="html4strict">

   

<html> <body> <button onclick="alert(Math.ceil(1.1));">Math.ceil(1.1): CEIL</button> </body> </html>


 </source>
   
  


"cos()" Example

   <source lang="html4strict">

   

<html> <body> <button onclick="alert(Math.cos(1));">Math.cos(1)</button> </body> </html>


 </source>
   
  


"E" Example

   <source lang="html4strict">

   

<html> <body> <button onclick="alert(Math.E);">Math.E</button> </body> </html>


 </source>
   
  


"exp()" Example

   <source lang="html4strict">

   

<html> <body> <button onclick="alert(Math.exp(1));">Math.exp(1)</button> </body> </html>


 </source>
   
  


"floor()" Example

   <source lang="html4strict">

   

<html> <body> <button onclick="alert(Math.floor(1.1));">Math.floor(1.1)</button> </body> </html>


 </source>
   
  


"isNaN()" Example

   <source lang="html4strict">

   

<html> <body> <button onclick="alert(isNaN("12.34"));">isNaN("12.34") True</button> <button onclick="alert(isNaN("Hello"));">isNaN("Hello") False</button> </body> </html>


 </source>
   
  


"LN10" Example

   <source lang="html4strict">

   

<html> <body> <button onclick="alert(Math.LN2);">Math.LN2</button> </body> </html>


 </source>
   
  


"LN2" Example

   <source lang="html4strict">

   

<html> <body> <button onclick="alert(Math.LN10);">Math.LN10</button> </body> </html>


 </source>
   
  


"LOG10E" Example

   <source lang="html4strict">

   

<html> <body> <button onclick="alert(Math.LOG10E);">Math.Log10E</button> </body> </html>


 </source>
   
  


"LOG2E" Example

   <source lang="html4strict">

   

<html> <body> <button onclick="alert(Math.LOG2E);">Math.Log2E</button> </body> </html>


 </source>
   
  


"log()" Example

   <source lang="html4strict">

   

<html> <body> <button onclick="alert(Math.log(1));">Math.log(1)</button> </body> </html>


 </source>
   
  


Math functions

   <source lang="html4strict">
   

Math Description Methods abs(x) Returns the absolute value of x. acos(x) Returns the arc cosine of x in radians. asin(x) Returns the arc sine of x in radians. atan(x) Returns the arc tangent of x in radians. atan2(y,x) Returns the arc tangent of the quotient of its Arguments, that is, y/x. ceil(x) Returns the smallest integer greater than or equal to x. cos(x) Returns the cosine of x. exp(x) Returns ex, where x is the Argument and e is Euler"s constant. floor(x) Returns the largest integer less than or equal to x. log(x) Returns the natural logarithm (base E) of x. max(x,y) Returns the greater of the two numbers x and y. min(x,y) Returns the lesser of the two numbers x and y. pow(x,y) Returns xy, traditionally base to the exponent power, that is, baseexponent. random() Returns a pseudo-random number between 0 and 1. round(x) Returns the value of x rounded to the nearest integer with .50 as cutoff. sin(x) Returns the sine of x. sqrt(x) Returns the square root of x. tan(x) Returns the tangent of x.



 </source>
   
  


"max()" Example

   <source lang="html4strict">

   

<html> <body> <button onclick="alert(Math.max(1, 2));">Math.max(1, 2)</button> </body> </html>


 </source>
   
  


"MAX_VALUE" Example

   <source lang="html4strict">

   

<html> <body> <button onclick="alert(Number.MAX_VALUE);">MAX_VALUE</button> <button onclick="alert(Number.MIN_VALUE);">MIN_VALUE</button> <button onclick="alert(Number.NEGATIVE_INFINITY);">NEGATIVE_INFINITY</button> <button onclick="alert(Number.POSITIVE_INFINITY);">POSITIVE_INFINITY</button> </body> </html>


 </source>
   
  


"min()" Example

   <source lang="html4strict">

   

<html> <body> <button onclick="alert(Math.min(1, 2));">Math.min(1, 2)</button> </body> </html>


 </source>
   
  


"MIN_VALUE" Example

   <source lang="html4strict">

   

<html> <body> <button onclick="alert(Number.MAX_VALUE);">MAX_VALUE</button> <button onclick="alert(Number.MIN_VALUE);">MIN_VALUE</button> <button onclick="alert(Number.NEGATIVE_INFINITY);">NEGATIVE_INFINITY</button> <button onclick="alert(Number.POSITIVE_INFINITY);">POSITIVE_INFINITY</button> </body> </html>


 </source>
   
  


"NEGATIVE_INFINITY" Example

   <source lang="html4strict">

   

<html> <body> <button onclick="alert(Number.MAX_VALUE);">MAX_VALUE</button> <button onclick="alert(Number.MIN_VALUE);">MIN_VALUE</button> <button onclick="alert(Number.NEGATIVE_INFINITY);">NEGATIVE_INFINITY</button> <button onclick="alert(Number.POSITIVE_INFINITY);">POSITIVE_INFINITY</button> </body> </html>


 </source>
   
  


"parseFloat()" Example

   <source lang="html4strict">

   

<html> <body> <button onclick="alert(parseFloat("12.34"));">parseFloat("12.34")</button> <button onclick="alert(parseFloat("Hello"));">parseFloat("Hello")</button> </body> </html>


 </source>
   
  


"parseInt()" Example

   <source lang="html4strict">

   

<html> <body> <button onclick="alert(parseInt("12.34"));">parseInt("12.34")</button> <button onclick="alert(parseInt("Hello"));">parseInt("Hello")</button> </body> </html>


 </source>
   
  


"PI" Example

   <source lang="html4strict">

   

<html> <body>

   <button onclick="alert(Math.PI);">Math.PI</button>

</body> </html>


 </source>
   
  


"POSITIVE_INFINITY" Example

   <source lang="html4strict">

   

<html> <body> <button onclick="alert(Number.MAX_VALUE);">MAX_VALUE</button> <button onclick="alert(Number.MIN_VALUE);">MIN_VALUE</button> <button onclick="alert(Number.NEGATIVE_INFINITY);">NEGATIVE_INFINITY</button> <button onclick="alert(Number.POSITIVE_INFINITY);">POSITIVE_INFINITY</button> </body> </html>


 </source>
   
  


"pow()" Example

   <source lang="html4strict">

   

<html> <body> <button onclick="alert(Math.pow(2,2));">Math.pow(2,2)</button> </body> </html>


 </source>
   
  


"round()" Example

   <source lang="html4strict">

   

<html> <body> <button onclick="alert(Math.round(1.33));">Math.round(1.33)</button> </body> </html>


 </source>
   
  


"sin()" Example

   <source lang="html4strict">

   

<html> <body> <button onclick="alert(Math.sin(1));">Math.sin(1)</button> </body> </html>


 </source>
   
  


"SQRT1_2" Example

   <source lang="html4strict">

   

<html> <body> <button onclick="alert(Math.SQRT1_2);">Math.Sqrt1_2</button> </body> </html>


 </source>
   
  


"SQRT2" Example

   <source lang="html4strict">

   

<html> <body> <button onclick="alert(Math.SQRT2);">Math.Sqrt2</button> </body> </html>


 </source>
   
  


"sqrt()" Example

   <source lang="html4strict">

   

<html> <body> <button onclick="alert(Math.sqrt(2));">Math.sqrt(2)</button> </body> </html>


 </source>
   
  


"tan()" Example

   <source lang="html4strict">

   

<html> <body> <button onclick="alert(Math.tan(1));">Math.tan(1) = ? </button> </body> </html>


 </source>