JavaScript |数学对象
Math 对象用于对数字执行数学运算。下面列出了许多数学对象属性:
Property | Description |
---|---|
Math.E | Euler’s number |
Math.PI | PI |
Math.SQRT2 | The square root of 2 |
Math.SQRT1_2 | The square root of 1/2 |
Math.LN2 | The natural logarithm of 2 |
Math.LN10 | The natural logarithm of 10 |
Math.LOG2E | Base 2 logarithm of E |
Math.LOG10E | Base 10 logarithm of E |
数学对象: JavaScript 中存在许多数学对象,如下所列:
Property | Description |
---|---|
abs(x) | Absolute value of x |
acos(x) | Arccosine of x, in radian |
asin(x) | Arcsine of x, in radian |
atan(x) | Arctangent of x, a numeric value between -PI/2 and PI/2 radian |
atan2(y, x) | Arctangent of the quotient of its arguments |
ceil(x) | Value of x rounded up to the nearest integer |
cos(x) | Cosine of x (x in radians) |
exp() | Value of E^x |
floor() | Value of x rounded below to the nearest integer |
log() | Natural logarithm (base E) of x |
max(a, b, …) | Highest value |
min(a, b, …) | Lowest value |
pow(x, y) | Value of x to power of y |
random() | Random number between 0 and 1 |
round(x) | Value of x rounded to the nearest integer |
sin(x) | Sine of x (x in radians) |
sqrt(x) | Square root of x |
tan(x) | Tangent of angle |
示例 1:此示例使用数学对象属性返回其值。
JavaScript Math Object
GeeksforGeeks
JavaScript Math Object
输出:
示例 2:此示例中使用了数学对象方法。
JavaScript Math Object
GeeksForGeeks
JavaScript Math Object
输出: