round function in APL to round a numeric value to a specified number of decimal places. When no precision is provided, the function rounds to the nearest integer.
round is useful for reducing noise in aggregated metrics, normalizing reported values to a readable precision, and comparing floating-point results that are intended to be equal but differ by tiny rounding errors. For example, you can round average latencies to two decimal places for display, or round computed percentages to integers for bucketing.
For users of other query languages
If you come from other query languages, this section explains how to adjust your existing queries to achieve the same results in APL.Splunk SPL users
Splunk SPL users
In Splunk SPL,
round(X, Y) rounds X to Y decimal places, just like APL’s round.ANSI SQL users
ANSI SQL users
In ANSI SQL,
ROUND(x, precision) works the same as APL’s round.Usage
Syntax
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
source | real | Yes | The value to round. |
Precision | int | No | Number of decimal places to round to. Defaults to 0. |
Returns
Thesource value rounded to the specified number of decimal places.
Example
Useround to round the average request duration to two decimal places per hour.
Query
| _time | avg_duration | avg_rounded |
|---|---|---|
| 2024-11-14 10:00:00 | 123.4567 | 123.46 |
| 2024-11-14 11:00:00 | 98.1234 | 98.12 |
| 2024-11-14 12:00:00 | 200.0001 | 200.00 |
List of related functions
- abs: Returns the absolute value. Use it to remove sign before rounding if direction is irrelevant.
- sign: Returns the sign of a value. Use it to check direction after rounding.
- log10: Returns the base-10 logarithm. Use
round(log10(x))to bucket values by integer order of magnitude. - pow: Raises a value to a power. Use it to scale values before rounding when working with non-unit precision.
- sqrt: Returns the square root. Combine with
roundto produce a rounded standard deviation or root value.