floor
This page explains how to use the floor function in APL.
Use the floor function to round a numeric value down to the largest integer less than or equal to the input. This function is useful when you need to ensure that fractional values always round down, such as when calculating completed intervals, resource consumption, or discrete counts.
Use floor when you want to convert decimal numbers to whole numbers by truncating the fractional part. For example, if a user has completed 2.7 sessions, floor returns 2 to represent fully completed sessions.
Usage
Syntax
floor(number)Parameters
| Name | Type | Description |
|---|---|---|
number | real | The numeric value to round down. |
Returns
An integer representing the largest whole number less than or equal to the input value.
Use case examples
Calculate completed seconds from millisecond durations.
Query
['sample-http-logs']
| extend completed_ms = floor(req_duration_ms)
| summarize request_count = count() by completed_ms
| order by completed_ms ascOutput
| completed_seconds | request_count |
|---|---|
| 0 | 8540 |
| 1 | 2310 |
| 2 | 890 |
| 3 | 245 |
This query converts request durations to whole milliseconds by rounding down, then groups requests by their completion time.
Group traces by completed duration intervals.
Query
['otel-demo-traces']
| extend duration_seconds = floor(duration / 1s)
| summarize trace_count = count() by duration_seconds, ['service.name']
| order by trace_count descOutput
| duration_seconds | service.name | trace_count |
|---|---|---|
| 0 | frontend | 1850 |
| 0 | frontend-proxy | 580 |
| 599 | load-generator | 420 |
| 600 | cart | 210 |
This query rounds span durations down to whole seconds to analyze the distribution of trace durations per service.
List of related functions
- ceiling: Rounds up to the smallest integer greater than or equal to the input. Use
floorwhen you need to round down instead. - bin: Rounds values down to a multiple of a specified bin size. Use
floorfor simple downward rounding to integers. - round: Rounds to the nearest integer or specified precision. Use
floorwhen you always need to round down.