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