math round for math
Returns the input number rounded to the specified precision.
Signature
> math round {flags} ...rest
Flags
--precision, -p {number}: Digits of precision.
Parameters
...rest: The cell-paths/columns to operate on.
Input/output types:
| input | output |
|---|---|
| number | number |
| duration | duration |
| filesize | filesize |
| list<number> | list<number> |
| list<duration> | list<duration> |
| list<filesize> | list<filesize> |
| range | list<number> |
| record | record |
Examples
Apply the round function to a list of numbers.
> [1.5 2.3 -3.1] | math round
╭───┬────╮
│ 0 │ 2 │
│ 1 │ 2 │
│ 2 │ -3 │
╰───┴────╯Apply the round function with precision specified.
> [1.555 2.333 -3.111] | math round --precision 2
╭───┬───────╮
│ 0 │ 1.56 │
│ 1 │ 2.33 │
│ 2 │ -3.11 │
╰───┴───────╯Apply negative precision to a list of numbers.
> [123, 123.3, -123.4] | math round --precision -1
╭───┬──────╮
│ 0 │ 120 │
│ 1 │ 120 │
│ 2 │ -120 │
╰───┴──────╯Apply the round function to list-valued columns in a record.
> {alice: [1.2 2.7 3.5], bob: [4.1 5.9]} | math round
╭───────┬───────────╮
│ │ ╭───┬───╮ │
│ alice │ │ 0 │ 1 │ │
│ │ │ 1 │ 3 │ │
│ │ │ 2 │ 4 │ │
│ │ ╰───┴───╯ │
│ │ ╭───┬───╮ │
│ bob │ │ 0 │ 4 │ │
│ │ │ 1 │ 6 │ │
│ │ ╰───┴───╯ │
╰───────┴───────────╯Apply the round function to a single column using a cell path.
> {alice: [1.2 2.7 3.5], bob: [4.1 5.9]} | math round alice
╭───────┬──────────────╮
│ │ ╭───┬───╮ │
│ alice │ │ 0 │ 1 │ │
│ │ │ 1 │ 3 │ │
│ │ │ 2 │ 4 │ │
│ │ ╰───┴───╯ │
│ │ ╭───┬──────╮ │
│ bob │ │ 0 │ 4.10 │ │
│ │ │ 1 │ 5.90 │ │
│ │ ╰───┴──────╯ │
╰───────┴──────────────╯Filesize values are already whole bytes, so rounding is a no-op.
> 2.1KB | math round
2.1 kBNotes
Filesize and duration values are stored as integers in base units (bytes and nanoseconds). With no display unit to round against, math round is the identity function for those types. --precision is not supported for filesize or duration.