Overview

round

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.

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.

Other query languages#

Splunk SPL users

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

Splunk example

| eval avg_duration_rounded = round(avg_duration, 2)

APL equivalent

['sample-http-logs']
| extend avg_duration_rounded = round(avg_duration, 2)
ANSI SQL users

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

SQL example

SELECT ROUND(avg_duration, 2) AS avg_duration_rounded FROM logs

APL equivalent

['sample-http-logs']
| extend avg_duration_rounded = round(avg_duration, 2)

Updated

Was this page helpful?