Math
Overview
Mathematical operations. It includes mathematical functions such as Math.abs, Math.pow, Math.ceil, Math.random, Math.sqrt, and Math.round
abs
Returns the absolute value of x
Math.abs(x)| Parameter | Type | Description |
|---|---|---|
| x | Integer or Double | Number to calculate absolute value |
Return Value
Type Integer or Double Absolute value of number x
Examples
Math.abs(-100.3) //100.3pow
Returns d1 raised to the power of d2
Math.pow(d1, d2)| Parameter | Type | Description |
|---|---|---|
| d1 | Integer or Double | Number to calculate the power of |
| d2 | Integer or Double | Exponent |
Return Value
Type Double Number d1 raised to the power of d2
Examples
Math.pow(2, 3) //8.0ceil
Returns the smallest integer greater than or equal to x
Math.ceil(x)| Parameter | Type | Description |
|---|---|---|
| x | Double | Number to compare |
Return Value
Type Double The smallest integer greater than or equal to x
TIP
- Note that the return type of the function is a decimal
Examples
Math.ceil(2.2) //3.0floor
Returns the largest integer less than or equal to x
Math.floor(x)| Parameter | Type | Description |
|---|---|---|
| x | Double | Number to compare |
Return Value
Type Double The largest integer less than or equal to x
TIP
- Note that the return type of the function is a decimal
Examples
Math.floor(2.2) //2random
Returns a random number between 0 and 1
Math.random()Return Value
Type Double A decimal greater than or equal to 0 and less than 1, returns a random number each time it is called
Examples
Math.random() //0.6260832016946124sqrt
Returns the square root of x
Math.sqrt(x)| Parameter | Type | Description |
|---|---|---|
| x | Double | Number to calculate the square root of |
Return Value
Type Double Square root of x
Examples
Math.sqrt(4) //2.0round
Returns the value of number n rounded to the nearest number with digits decimal places
Math.round(n, digits)| Parameter | Type | Description |
|---|---|---|
| n | Double | Number to round |
| digits | Integer | Number of decimal places for precision |
Return Value
Type Double Rounded value
Examples
Math.round(3.1415926, 2)//3.14
Math.round(3.1415926, 4)//3.1416
