> ## Documentation Index
> Fetch the complete documentation index at: https://numpyts.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Rounding

> Element-wise rounding, floor, ceiling, and truncation functions.

### around

Round an array to the given number of decimals.

```typescript theme={null}
function around(a: NDArray, decimals?: number): NDArray
```

| Name | Type | Default | Description |
| - | - | - | - |
| `a` | `NDArray` | - | Input array. |
| `decimals` | `number` | `0` | Number of decimal places to round to. `0` rounds to the nearest integer. Negative values round to powers of ten (e.g., `-1` rounds to the nearest 10). |

**Returns:** `NDArray` -- Array with each element rounded to the given number of decimals.

> [!NOTE]
>
> Changed in v1.7.0: integer input with `decimals >= 0` has nothing to round, so it now comes back as a view of the input rather than a copy. This matches NumPy. Writes to the result reach the input array, so call `.copy()` if you need an independent buffer. `base` is set on exactly the results that alias.

```typescript Full Library theme={null}
import * as np from 'numpy-ts';

const a = np.around(np.array([1.234, 2.567, 3.891]), 2);
// array([1.23, 2.57, 3.89])

const b = np.around(np.array([1.5, 2.5, 3.5]));
// array([2, 2, 4])  -- banker's rounding

const c = np.around(np.array([123, 456, 789]), -2);
// array([100, 500, 800])
```

```typescript Core theme={null}
import { around, array } from 'numpy-ts/core';

const a = around(array([1.234, 2.567, 3.891]), 2);
const b = around(array([1.5, 2.5, 3.5]));
```

***

### round

Alias for [`around`](#around). Round an array to the given number of decimals.

```typescript theme={null}
function round(a: NDArray, decimals?: number): NDArray
```

| Name | Type | Default | Description |
| - | - | - | - |
| `a` | `NDArray` | - | Input array. |
| `decimals` | `number` | `0` | Number of decimal places. |

**Returns:** `NDArray` -- Rounded array.

> [!NOTE]
>
> Changed in v1.7.0: integer input with `decimals >= 0` has nothing to round, so it now comes back as a view of the input rather than a copy. This matches NumPy. Writes to the result reach the input array, so call `.copy()` if you need an independent buffer. `base` is set on exactly the results that alias.

```typescript Full Library theme={null}
import * as np from 'numpy-ts';

const a = np.round(np.array([0.123, 4.567, 8.901]), 1);
// array([0.1, 4.6, 8.9])
```

```typescript Core theme={null}
import { round, array } from 'numpy-ts/core';

const a = round(array([0.123, 4.567, 8.901]), 1);
```

***

### ceil

Return the ceiling of each element (smallest integer greater than or equal to each value).

```typescript theme={null}
function ceil(x: NDArray): NDArray
```

| Name | Type | Default | Description |
| - | - | - | - |
| `x` | `NDArray` | - | Input array. |

**Returns:** `NDArray` -- Element-wise ceiling.

```typescript Full Library theme={null}
import * as np from 'numpy-ts';

const a = np.ceil(np.array([1.1, 1.9, -1.1, -1.9]));
// array([2, 2, -1, -1])
```

```typescript Core theme={null}
import { ceil, array } from 'numpy-ts/core';

const a = ceil(array([1.1, 1.9, -1.1, -1.9]));
```

***

### floor

Return the floor of each element (largest integer less than or equal to each value).

```typescript theme={null}
function floor(x: NDArray): NDArray
```

| Name | Type | Default | Description |
| - | - | - | - |
| `x` | `NDArray` | - | Input array. |

**Returns:** `NDArray` -- Element-wise floor.

```typescript Full Library theme={null}
import * as np from 'numpy-ts';

const a = np.floor(np.array([1.1, 1.9, -1.1, -1.9]));
// array([1, 1, -2, -2])
```

```typescript Core theme={null}
import { floor, array } from 'numpy-ts/core';

const a = floor(array([1.1, 1.9, -1.1, -1.9]));
```

***

### fix

Round to the nearest integer toward zero.

```typescript theme={null}
function fix(x: NDArray): NDArray
```

| Name | Type | Default | Description |
| - | - | - | - |
| `x` | `NDArray` | - | Input array. |

**Returns:** `NDArray` -- Element-wise value rounded toward zero (truncation toward zero).

```typescript Full Library theme={null}
import * as np from 'numpy-ts';

const a = np.fix(np.array([2.7, -2.7, 0.5, -0.5]));
// array([2, -2, 0, 0])
```

```typescript Core theme={null}
import { fix, array } from 'numpy-ts/core';

const a = fix(array([2.7, -2.7, 0.5, -0.5]));
```

***

### rint

Round to the nearest integer, element-wise.

```typescript theme={null}
function rint(x: NDArray): NDArray
```

| Name | Type | Default | Description |
| - | - | - | - |
| `x` | `NDArray` | - | Input array. |

**Returns:** `NDArray` -- Element-wise value rounded to the nearest integer.

```typescript Full Library theme={null}
import * as np from 'numpy-ts';

const a = np.rint(np.array([1.2, 1.5, 1.8, 2.5]));
// array([1, 2, 2, 2])
```

```typescript Core theme={null}
import { rint, array } from 'numpy-ts/core';

const a = rint(array([1.2, 1.5, 1.8, 2.5]));
```

***

### trunc

Return the truncated value of each element (drop the fractional part).

```typescript theme={null}
function trunc(x: NDArray): NDArray
```

| Name | Type | Default | Description |
| - | - | - | - |
| `x` | `NDArray` | - | Input array. |

**Returns:** `NDArray` -- Element-wise integer part. Equivalent to `fix`.

```typescript Full Library theme={null}
import * as np from 'numpy-ts';

const a = np.trunc(np.array([1.7, -1.7, 0.3, -0.3]));
// array([1, -1, 0, 0])
```

```typescript Core theme={null}
import { trunc, array } from 'numpy-ts/core';

const a = trunc(array([1.7, -1.7, 0.3, -0.3]));
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.