Math (arithmetic) objects are used to execute common arithmetic tasks.
Instance
-
Round ()
-
How to use round ().
-
Random ()
-
How to use random () to return a random number between 0 and 1.
-
Max ()
-
How to Use max () to return a large number of two given numbers.
-
Min ()
-
How to Use min () to return a small number of two given numbers.
Complete math Object Reference Manual
We provide reference manuals for JavaScript math objects, including all the attributes and methods that can be used for array objects.
This Manual contains a detailed description of each attribute and method and related examples.
Math object
Math (arithmetic) objects are used to execute common arithmetic tasks.
The math object provides multiple numeric types and functions. You do not need to define this object before using it.
Calculate the value
Javascript provides eight computing values that can be accessed by math objects:
- Constant
- Circumference Rate
- Square root of 2
- Square root of 1/2
- Natural logarithm of 2
- Natural logarithm of 10
- Base-2 logarithm of E
- Base-10 logarithm of E
This is a method to use these values in javascript: (one-to-one correspondence with the preceding calculated values)
- Math. e
- Math. Pi
- Math. sqrt2
- Math. sqrt1_2
- Math. ln2
- Math. ln10
- Math. log2e
- Math. log10e
Arithmetic Method
In addition to the value that can be accessed by the math object, there are several functions (methods) that can be used.
Function (method) instance:
The following example uses the round method of the math object to round a number.
document.write(Math.round(4.7)
)
The above code output is:
5
The following example uses the random () method of the math object to return a random number between 0 and 1:
document.write(Math.random()
)
The above code output is:
0.9370844220218102
The following example uses the floor () method and random () of the math object to return a random number between 0 and 10:
document.write(Math.floor(Math.random()*11)
)
The above code output is:
3