Skip to main content
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.
| eval avg_duration_rounded = round(avg_duration, 2)
In ANSI SQL, ROUND(x, precision) works the same as APL’s round.
SELECT ROUND(avg_duration, 2) AS avg_duration_rounded FROM logs

Usage

Syntax

round(source [, Precision])

Parameters

NameTypeRequiredDescription
sourcerealYesThe value to round.
PrecisionintNoNumber 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
_timeavg_durationavg_rounded
2024-11-14 10:00:00123.4567123.46
2024-11-14 11:00:0098.123498.12
2024-11-14 12:00:00200.0001200.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.