round
This page explains how to use the round function in APL.
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.
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_roundedOutput
| _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.