JavaScript Class
The Math object
The Math object includes mathematical constants and functions. You do not need to create the Math object before using it.
To store a random number between 0 and 1 in a variable called "r_number":
To store the rounded number of 8.6 in a variable called "r_number":
The Math object's properties and methods are described below:
NN: Netscape, IE: Internet Explorer, ECMA: Web Standard
Methods |
Explanation |
NN |
IE |
ECMA |
abs(x) |
Returns the absolute value of x |
2.0 |
3.0 |
1.0 |
floor(x) |
Returns the nearest integer less than or equal to x |
2.0 |
3.0 |
1.0 |
max(x,y) |
Returns the number with the highest value of x and y |
2.0 |
3.0 |
1.0 |
min(x,y) |
Returns the number with the lowest value of x and y |
2.0 |
3.0 |
1.0 |
pow(x,y) |
Returns the value of the number x raised to the power of y |
2.0 |
3.0 |
1.0 |
random() |
Returns a random number between 0 and 1 |
2.0 |
3.0 |
1.0 |
round(x) |
Rounds x to the nearest integer |
2.0 |
3.0 |
1.0 |
sqrt(x) |
Returns the square root of x |
2.0 |
3.0 |
1.0 |
|