This site has been taken over by the staff of www.ASPDeveloper.Net

Please report errors to suggest@aspdeveloper.net

BizTalk Utilities CV ,   Jobs ,   Code library  
 
Home Page
JavaScript
JavaScript Math Object
JavaScript Functions
JavaScript Form
JavaScript Error (try/catch/finally)
JavaScript Date Object Functions
JavaScript Date Object
JavaScript Loops
JavaScript Operators
JavaScript Conditional Statements
JavaScript Boolean Object
JavaScript Assertiveness
JavaScript Array Object Functions
JavaScript Arrays
JavaScript Variables
How to use JavaScript?
JavaScript Guidelines
Stock sorter example for IE5
Confused about how to use a data island in IE5??
Software Release tracking application
Employee Phonebook dataisland
 
LAMP >>

By :Mark Wilson
I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
First posted :03/24/2008
Times viewed :6907

 

JavaScript Math Object Functions

Introduction

The Math object contains 16 functions. In this section you will see these 16 functions in some small examples. Please take a look at the math object, if you need more information about that. All functions are used with the Math object. The following examples demonstrate this.

JavaScript abs Function
JavaScript sin Function
JavaScript cos Function
JavaScript tan Function
JavaScript acos Function
JavaScript asin Function
JavaScript atan Function
JavaScript exp Function
JavaScript ceil Function
JavaScript floor Function
JavaScript min Function
JavaScript max Function
JavaScript pow Function
JavaScript round Function
JavaScript random Function

JavaScript abs Function

This abs function can be used to return the absolute value.

<html>

<head>

<script type="text/javascript">

            var x = 100.56

            x = Math.abs(x)

            document.write(x)

</script>

</head>

<body></body>

</html>

Output

100.56

JavaScript sin Function

The sin function returns the sinus of the value.

<html>

<head>

<script type="text/javascript">

            var x = 100

            x = Math.sin(x)

            document.write(x)

</script>

</head>

<body></body>

</html>

Output

-0.5063656411097588

JavaScript cos Function

The cos function returns the cosinus of a value.

<html>

<head>

<script type="text/javascript">

            var x = 100

            x = Math.cos(x)

            document.write(x)

</script>

</head>

<body></body>

</html>

Output

0.8623188722876839

JavaScript tan Function

<html>

<head>

<script type="text/javascript">

            var x = 100

            x = Math.tan(x)

            document.write(x)

</script>

</head>

<body></body>

</html>

Output

-0.5872139151569291

JavaScript acos Function

The acos function can be used to return arccosine in the radians of a number.

<html>

<head>

<script type="text/javascript">

            var x = -1

            x = Math.acos(x)

            document.write(x)

</script>

</head>

<body></body>

</html>

Output

3.141592653589793

JavaScript asin Function

The asin function returns the arcsine of arctangent in radians.

<html>

<head>

<script type="text/javascript">

            var x = -1

            x = Math.asin(x)

            document.write(x)

</script>

</head>

<body></body>

</html>

Output

-1.5707963267948965

JavaScript atan Function

The atan function returns the arcsine of arctangent in radians.

<html>

<head>

<script type="text/javascript">

            var x = -1

            x = Math.atan(x)

            document.write(x)

</script>

</head>

<body></body>

</html>

Output

-0.7853981633974483

JavaScript exp Function

The exp function can be used to return the exponential number.

<html>

<head>

<script type="text/javascript">

            var x = 100

            x = Math.exp(x)

            document.write(x)

</script>

</head>

<body></body>

</html>

Output

2.6881171418161356e+43

JavaScript ceil Function

The ceil function rounds up a decimal number to the next largest number.

<html>

<head>

<script type="text/javascript">

            var x = 1.5

            x = Math.ceil(x)

            document.write(x)

</script>

</head>

<body></body>

</html>

Output

2

JavaScript floor Function

The floor function rounds the number to the next lowest number.

<html>

<head>

<script type="text/javascript">

            var x = 1.5

            x = Math.floor(x)

            document.write(x)

</script>

</head>

<body></body>

</html>

Output

1

JavaScript min Function

The min function returns the lesser of two numbers.

<html>

<head>

<script type="text/javascript">

            x = Math.min(19, 20)

            document.write(x)

</script>

</head>

<body></body>

</html>

Output

19

JavaScript max Function

The min function returns the greater of two numbers.

<html>

<head>

<script type="text/javascript">

            x = Math.max(19, 20)

            document.write(x)

</script>

</head>

<body></body>

</html>

Output

20

JavaScript pow Function

The pow(x,y) function returns the value of x to the power of y.

<html>

<head>

<script type="text/javascript">

            x = Math.pow(3,2)

            document.write(x)

</script>

</head>

<body></body>

</html>

Output

9

JavaScript round Function

The round function rounds up the number to the closest number.

<html>

<head>

<script type="text/javascript">

            var x = 1.2

            x = Math.round(x)

            document.write(x)

</script>

</head>

<body></body>

</html>

Output

1

JavaScript random Function

The random function returns a random number between 0 and 1.

<html>

<head>

<script type="text/javascript">

            x = Math.random()

            document.write(x)

</script>

</head>

<body></body>

</html>

Output

Of course the output may differ on your system.

0.972552248872969


Rate this article on a scale of 1 to 10

Your vote :  


 

Recent Jobs

Software Specialist, Linux - Finlan
Linux Core Technical Project Manage
Graphics designer at Tanzania. Expe
Integration Specialist Needed - Wor
Virtualization Server Infrastructur

View all Jobs (Add yours)
View all CV (Add yours)






    Email TopXML  

Front Page Daily Stuff TopXML Forum XML blogs XML Newsgroups BizTalk Biztalk Utilities Biztalk Utilities Tutorial B2B SAP XML Microsoft .NET Dotnet System XML Soapformatter SQLXML XMLserializer XQuery PHP PHP SimpleXML PHP XML Dom PHP XML RPC PHP XSLT Java Java Java XML Xalan Microsoft ASP ASP Schemas XML SQL Server XML XMLDom XSL XSL Tutorial XSLT Stylesheets General Javascript CSS XHTML WAP