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

# Rounding and numeric

> Rounding, truncation, absolute value, sign, and integer/fractional-part functions.

These functions adjust or inspect a number's value. Each accepts a number or a [table](https://docs.truemath.ai/math/types/tables.md), returning the same shape, and a [unit](https://docs.truemath.ai/math/units.md) on the value is carried through to the result. [`sign`](#sign-sign) is the exception: it reports a direction, so it returns a bare number.

> [!WARNING]
>
> **Round only when you mean to change the value.** TrueMath carries values at [full precision](https://docs.truemath.ai/concepts/units-and-precision.md) through every step. `round`, `floor`, and `ceil` permanently discard that precision, and a rounded value used in a later calculation introduces error that compounds across steps. They also change the value an [activity](https://docs.truemath.ai/concepts/activities.md) returns, which can make it impossible to solve in reverse.
>
> To show fewer decimals without losing precision, set the [variable's](https://docs.truemath.ai/concepts/variables.md) format instead of rounding.

## Round \[round]

```
round(value)
round(value; places)
round(date; "unit")
```

Rounds to `places` following standard rounding (digits 0–4 round down, 5–9 round up). Set `places` to `1`–`10` to round to that decimal place, or `0` to `-10` to round to a whole-number place; it defaults to `0`. `places` must be a whole number in the range -10 to 10 (real numbers are truncated); outside that range returns a `Parameter out of range` error.

Given a [date](https://docs.truemath.ai/math/types/dates.md) and a quoted time unit, `round` snaps to the nearest boundary of that unit instead — see [Snapping a date to a boundary](#snapping-a-date-to-a-boundary).

```
round(1234.56)         => 1235
round(1234.56; 1)      => 1234.6
round(1234.56; -2)     => 1200
round(5.567m; 1)       => 5.6 m
round(1234.56USD; -2)  => 1200 USD
```

## Floor \[floor]

```
floor(value)
floor(value; places)
floor(date; "unit")
```

The largest value less than or equal to `value` at the given `places`. `places` follows the same rules as [`round`](#round-round). Given a [date](https://docs.truemath.ai/math/types/dates.md) and a quoted time unit, `floor` snaps back to the boundary at or before the date — see [Snapping a date to a boundary](#snapping-a-date-to-a-boundary).

```
floor(23.456)        => 23
floor(23.567)        => 23
floor(-23.456)       => -24
floor(-23.567)       => -24
floor(1234.56; 1)    => 1234.5
floor(1234.56; -2)   => 1200
floor(5.9m)          => 5 m
```

## Ceiling \[ceil]

```
ceil(value)
ceil(value; places)
ceil(date; "unit")
```

The smallest value greater than or equal to `value` at the given `places`. `places` follows the same rules as [`round`](#round-round). Given a [date](https://docs.truemath.ai/math/types/dates.md) and a quoted time unit, `ceil` snaps forward to the boundary at or after the date — see [Snapping a date to a boundary](#snapping-a-date-to-a-boundary).

```
ceil(23.456)         => 24
ceil(23.567)         => 24
ceil(-23.456)        => -23
ceil(-23.567)        => -23
ceil(1234.56; 1)     => 1234.6
ceil(1234.56; -2)    => 1300
ceil(5.1m)           => 6 m
```

## Snapping a date to a boundary

When the first argument is a [date](https://docs.truemath.ai/math/types/dates.md), all three functions accept a **quoted time unit** in place of `places`, which snaps the date to that unit's boundary — the start of the day, the first of the month, the nearest hour.

```
floor(date; "unit")
ceil(date; "unit")
round(date; "unit")
```

A boundary is the instant a period **starts** — the year boundaries are January 1 at midnight, the month boundaries are the 1st at midnight, the day boundaries are midnight. Snapping zeros every component finer than the unit named. Six units are accepted, one per calendar component:

| `unit` | Boundary | `floor(date(2026; 7; 21; 9; 30; 45); "unit")` |
| - | - | - |
| `"s"` | whole second | 2026-07-21 09:30:45 |
| `"min"` | start of the minute | 2026-07-21 09:30:00 |
| `"hr"` | start of the hour | 2026-07-21 09:00:00 |
| `"d"` | start of the day | 2026-07-21 00:00:00 |
| `"mo"` | first of the month | 2026-07-01 00:00:00 |
| `"yr"` | January 1 | 2026-01-01 00:00:00 |

Those six are the whole set, because each names a calendar component that can be zeroed. `"wk"` is not among them — a week is not a component of a date — and a unit from another dimension, such as `"m"` or `"lb"`, returns `input.incompatible_units`.

Because boundaries are period starts, `ceil` moves **forward to the start of the next period**, not to the last day of the current one: `ceil(d; "yr")` on any date in 2026 is January 1, 2027, and `ceil(d; "mo")` on July 21 is August 1. December 31 is not a year boundary — it is the last day inside the year, which is a different thing. To get the last day of a period, take the next boundary and step back a day with [`adjdate`](https://docs.truemath.ai/math/functions/dates#calendar-adjustment-adjdate):

```
adjdate(ceil(date(2026; 7; 21; 9; 30); "mo"); -1)   => date(2026; 7; 31)
adjdate(ceil(date(2026; 7; 21; 9; 30); "yr"); -1)   => date(2026; 12; 31)
```

A date already exactly on a boundary is returned unchanged by both `floor` and `ceil`, so applied to `date(2026; 8; 1)` that idiom gives July 31 — the previous period's last day. Snap or offset first if the input might land on a boundary.

```
floor(date(2026; 7; 21; 9; 30); "d")    => date(2026; 7; 21)
ceil(date(2026; 7; 21; 9; 30); "d")     => date(2026; 7; 22)
floor(date(2026; 7; 21; 9; 30); "mo")   => date(2026; 7; 1)
ceil(date(2026; 7; 21; 9; 30); "yr")    => date(2027; 1; 1)
round(date(2026; 7; 21; 9; 30); "d")    => date(2026; 7; 21)
round(date(2026; 7; 21; 13; 30); "d")   => date(2026; 7; 22)
```

With no second argument at all, `floor` and `ceil` still act on the number, and for a date that means the whole second — `floor(d)` and `floor(d; "s")` agree.

Snapping is also how dates are compared at a coarser granularity than the exact instant. Two dates are equal only when their values match to the second, so snap both sides to the same unit and compare the results:

```
floor(date(2026; 7; 21; 9; 30); "d") == floor(date(2026; 7; 21; 16; 45); "d")   => true
floor(date(2026; 7; 21; 9; 30); "mo") == floor(date(2026; 7; 28; 3; 15); "mo")  => true
```

## Absolute value \[abs]

```
abs(value)
```

The absolute (non-negative) value.

```
abs(34)          => 34
abs(-34)         => 34
abs([25; -34])   => [25; 34]
abs(-3kg)        => 3 kg
```

## Sign \[sign]

```
sign(value)
```

`-1` if `value` is negative, `0` if zero, `1` if positive. The result is a bare number even when `value` carries a unit — it is a direction, not a quantity.

```
sign(34.567)             => 1
sign(-34.567)            => -1
sign(0)                  => 0
sign([25; -34; 0; 15])   => [1; -1; 0; 1]
sign(-5USD)              => -1
```

## Integer part \[ipart]

```
ipart(value)
```

The integer (whole-number) portion of `value`.

```
ipart(34.567)                     => 34
ipart([10.55; 8.7; -4.1; 3.25])   => [10; 8; -4; 3]
ipart(5.75m)                      => 5 m
```

## Fractional part \[fpart]

```
fpart(value)
```

The fractional (decimal) portion of `value`.

```
fpart(34.567)                     => 0.567
fpart([10.55; 8.7; -4.1; 3.25])   => [0.55; 0.7; -0.1; 0.25]
fpart(5.75m)                      => 0.75 m
```


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