1 |
|
2 |
|
3 | # Function round
|
4 |
|
5 | Round a value towards the nearest integer.
|
6 | For matrices, the function is evaluated element wise.
|
7 |
|
8 |
|
9 | ## Syntax
|
10 |
|
11 | ```js
|
12 | math.round(x)
|
13 | math.round(x, n)
|
14 | ```
|
15 |
|
16 | ### Parameters
|
17 |
|
18 | Parameter | Type | Description
|
19 | --------- | ---- | -----------
|
20 | `x` | number | BigNumber | Fraction | Complex | Array | Matrix | Number to be rounded
|
21 | `n` | number | BigNumber | Array | Number of decimals Default value: 0.
|
22 |
|
23 | ### Returns
|
24 |
|
25 | Type | Description
|
26 | ---- | -----------
|
27 | number | BigNumber | Fraction | Complex | Array | Matrix | Rounded value
|
28 |
|
29 |
|
30 | ## Examples
|
31 |
|
32 | ```js
|
33 | math.round(3.2) // returns number 3
|
34 | math.round(3.8) // returns number 4
|
35 | math.round(-4.2) // returns number -4
|
36 | math.round(-4.7) // returns number -5
|
37 | math.round(math.pi, 3) // returns number 3.142
|
38 | math.round(123.45678, 2) // returns number 123.46
|
39 |
|
40 | const c = math.complex(3.2, -2.7)
|
41 | math.round(c) // returns Complex 3 - 3i
|
42 |
|
43 | math.round([3.2, 3.8, -4.7]) // returns Array [3, 4, -5]
|
44 | ```
|
45 |
|
46 |
|
47 | ## See also
|
48 |
|
49 | [ceil](ceil.md),
|
50 | [fix](fix.md),
|
51 | [floor](floor.md)
|