Math Object

By: aathishankaran Emailed: 1785 times Printed: 2615 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

For mathematical calculations, JavaScript encapsulates a host of mathematical constants and procedures into a single entity-the Math object. The Math object is quite a bit different from the other built-in objects. First, you can perform basic arithmetic calculations (addition, sub-traction, multiplication, and division) outside a Math object, so unless you regularly require advanced math functions, you might rarely use it. 

Few developers might need to tap into the true power of the Math object, but for those who do, its capabilities are vital. Rather than pass values back to the server to perform mathematical calculations, you can use the Math object to perform advanced math processing on the client side.

Second, although you can create instances of String, Array, and Date objects using new, you work with a built-in instance of the Math object. This quality of the Math object parallels the Navigator object, for example, which is not created on-the-fly. Consequently, the Math object is commonly referred to as a static object. 

Do not confuse the Math object as a "number" object. The Math object is used for calculations only; it is not intended to be used as a representative for a number as a String object is commonly used in place of a string literal. It can be confusing because unlike the string, there is no number object per se. A number (either an integer or floating point) is recognized as a distinct data type, but it is not an object type. 

The Math object's properties are really nothing more than a list of common mathematical constants. Note the case of the constants. Although nearly all JavaScript properties are typically lowercase or mixed case, these properties are all uppercase. 

Math object properties 

Property Returns Description

E

LN2

LN10

LOG2E

LOG10E

PI

SQRT1_2

SQRT2

2.718281828

0.693147181

2.302585093

1.442695041

0.434294482

3.141592654

0.707106781

1.414213562

Euler's constant

Natural log of 2

Natural log of 10

Log base -2 of E

Log base -10 of E

Pi

Square root of 0.5

Square root of 2

 

Method Returns

abs(value)

acos(value).

asin(vaJue)

atan(value)

ceil(value)

cos(value)

exp(value)

floor(value)

log(value)

max(value1, value2)

min(value1, value2)

pow(value1, value2)

random()

round(value)

sin(value)

sqrt(value)

tan(value)

Absolute value of value

Arc cosine of value (in radians)

Arc sine of value (in radians)

Arc tangent of value (in radians)

Next integer >= value

Cosine of value

Euler's constant to the power of value

Next integer <= value

Natural logarithm of value (base e)

The highest number of value1 or value2

The lowest number of value1 or value2

value1 to the value2 power

A random number between 0 and 1

n + 1 (if value >= n.5; else n)

Sine of value (in radians)

Square root of value

Tangent of value (in radians)

 

Example:

<Html>

<Head><Title>Date Object</Title></Head>

<Body >

<H1>Math Object</H1>

<Hr>

<Script>

document.write("<B>");

document.write("<Br>");document.write("<Br>") ;

document.write("Absolute value of value : "+Math.abs(-10) ) ;

document.write("<Br>");document.write("<Br>") ;

document.write("Arc cosine of value (in radians) : "+Math.acos(.5) );

document.write("<Br>");document.write("<Br>") ;

document.write("Arc sine of value (in radians) : "+Math.asin(O.5) );

document.write("<Br>");document.write("<Br>");

document.write("Arc tangent of value (in radians) :"+Math.atan(0.5) );

document.write("<Br>");document.write("<Br>");

document.write ("Next integer >= value: "+Math.ceil(10.4));

document.write ("<Br>") ;document".write ("<Br>") ;

document.write("Cosine of value: "+Math.cos(90));

document.write ("<Br>") ;document.write("<Br>") ;

document.write(" Euler's constant to the power of value: "+Math.exp(5)) ;

document.write("<Br>");document.write("<Br>");

document.write ("Next integer <= value: "+Math.floor (10.4) ) ;

document.write("<Br>");document.write("<Br>") ;

document.write(" Natural logarithm of value (base e) :"+Math.log (20)) ;

document.write ("<Br>") ;document.write("<Br>");

document.write ("The highest number of value1 or value2 "+Math.max(9540, 10000));

document.write ("<Br>") ;document.write("<Br>");

document.write (" The lowest number of value1 or value2 : "+Math.min(500,450));

document.write ("<Br>") ;document.write("<Br>") ;

document.write(" value1 to the value2 power "+Math.pow(2,2));

document.write("<Br>");document.write("<Br>") ;

document.write("A random number between 0 and 1 :"+Math.random() );

document.write ("<Br>") ;document.write("<Br>");

document.write("n + 1 (if value >= n.5; else n) : "+Math.round(10.99) );

document.write ("<Br>") ;document.write("<Br>") ;

document.write(" Sine of value (in radians) "+Math.sin (90)) ;

document.write ("<Br>") ;document.write("<Br>");

document.write("Square root of value: "+Math.sqrt(9));

document.write ("<Br>") ;document.write ("<Br>") ;

document.write ("Tangent of value (in radians) "+Math.tan(90) );

document.write ("<Br>") ;document.write ("<Br>") ;

document.write("<hr>");

document.write("</B>");

</Script>

</Body>

</Html>

 


JSP Home | All JSP Tutorials | Latest JSP Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(0)


Be the first one to add a comment

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by aathishankaran
Web Security Issues
The Web User's Perspective
Server-side plug-Ins
The best way to avoid security vulnerabilities with new server
JavaScript Security
Window Object
Working with Status Bar Messages
Retrieving a Portion of a String
Referencing Windows
Math Object
Frame Object
Document Object
Closing Windows
Built-in Object in Javascript
Textarea Object

More Tutorials in JSP
LifecycleException: service.getName(): "Catalina"; Protocol handler start failed: `java.net.BindException: Permission denied <null>:80
JSP Alert Example
JSP CheckBox Example
Uploading an Image to a Database using JSP
Uploading a file to a server using JSP
A JSP page that gets properties from a bean
The page Directive in JSP
The taglib, tag, include, attribute and the variable Directive in JSP
Declarations in JSP
Scriptlets and Expressions in JSP
Tag Libraries in JSP
The Request Object in JSP
The Response Object in JSP
The Out Object in JSP
The Session Object in JSP

More Latest News
Most Viewed Articles (in JSP )
JSP Example to connect to MS SQL database and retrieve records
What are the different scopes in JSP?
JSP CheckBox Example
JSP Alert Example
Comparison operators in JSP
Sending Email using JSP
Uploading an Image to a Database using JSP
Arithmetic Evaluation Using the Expression Language in JSP
The Advantages of JSP
Disabling Scriptlets in JSP using web.xml
The Request Object in JSP
Writing your first JSP page
Uploading a file to a server using JSP
Deploying an Individual JSP on Tomcat
Automatically Refreshing a JSP
Most Emailed Articles (in JSP)
Calling JSP from a batch file
Simple HTML-Building Utilities
Handling Events
The Tag Life Cycle with Attributes in JSP
JSP Program for display Date
Sessions in JSP
NetworkClient
The Advantages of JSP
Using a DataSource from WebLogic in a JSP
The JSP Program running first Time.
JSP pages in servlet
Combining Scriptlets with HTML
Declaring variable in JSP
An Example Using Servlet Initialization and Page Modification Dates
Password Object