Use the 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.

In Splunk SPL, round(X, Y) rounds X to Y decimal places, just like APL's round.

```sql Splunk example | eval avg_duration_rounded = round(avg_duration, 2) ````
['sample-http-logs']
| extend avg_duration_rounded = round(avg_duration, 2)

In ANSI SQL, ROUND(x, precision) works the same as APL's round.

```sql SQL example SELECT ROUND(avg_duration, 2) AS avg_duration_rounded FROM logs ```
['sample-http-logs']
| extend avg_duration_rounded = round(avg_duration, 2)

Usage

Syntax

round(source [, Precision])

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

The source value rounded to the specified number of decimal places.

Example

Use round to round the average request duration to two decimal places per hour.

Query

['sample-http-logs']
| summarize avg_duration = avg(req_duration_ms) by bin(_time, 1h)
| extend avg_rounded = round(avg_duration, 2)
| project _time, avg_duration, avg_rounded

Run in Playground

Output

_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
  • 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 round to produce a rounded standard deviation or root value.

Good evening

I'm here to help you with the docs.

I
AIBased on your context