|
Java-Script Tutorial |
Introduction |
Variables |
Operators |
Statements |
Loops |
Functions |
Objects |
Arrays |
Browser Objects |
Form DOM |
Ask Your Doubts |
Feedback |
|
|
|
| |
|
|
Topic |
Methods available in Math Object for basic calculation in javascript?
|
|
Explanation |
Object: Math Methods
Math object has the following methods that can be used to do specific & basic operations like
getting random numbers, rounding a number, square root calculation, etc.. in javascript
The below table lists the methods that are available for math calculations
| Constant | Example Code | Result | Description |
| abs(value) |
Math.abs(2.822); |
| abs() method returns the absolute value of the argument passed.
|
| ceil(value) |
Math.ceil(3.44); |
| ceil() method returns the nearest greater integer value of the value passed as argument.
The argument can be an integer or float.
|
| floor(value) |
Math.floor(2.44); |
| floor() method returns the nearest lowest (least) integer value of
the argument passed.
|
| log(value) |
Math.log(3); | -
|
Result:
log(x) function returns the natural logarithm of the value used.
|
| max(value1, value2) |
Math.max(14, 12); |
| Math.max(value1, value2) compares the two values and
returns the maximum value of the two values passed.
|
| min(value1, value2) |
Math.min(14, 12); |
| Math.min(value1, value2) compares the two values and
returns the minimum value of the two values passed.
|
| pow(value1, value2) |
Math.pow(4, 2); |
| Math.pow(value1, value2) function is used to calculate xy
calculation. Here it is 42.
|
| random() |
Math.random(); |
| Math.random() gives a random value between 0 and 1. more...
|
| round() |
Math.round(9.678); |
| Math.round() function is used to round a float (decimal) value to the nearest integer value.
i.e. round of 4.5 will give 5, rounding of 4.4 will give 4.
|
These functions can be used for rounding a number to the nearest greater, lowest values, comparing two numbers,
finding log, absolute value, etc.... Next we will look in to function of math object that can be used for
trigonometric calculations.
|
Javascript (JS) is one of the most used languages in the world. Some times spelled as Java Script.
Hope you enjoy this tutorial. Do send your feedback or suggestions on this javascript or java script tutorial. This is a copyright content.
|
|
|
|