format_bytes function formats a numeric value as a human-readable string representing data size in bytes with appropriate units (KB, MB, GB, etc.). Use this function to make byte values more readable in reports, dashboards, and log analysis.
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.Splunk SPL users
Splunk SPL users
In Splunk SPL, you typically need custom eval expressions or lookup tables to format bytes. APL’s
format_bytes provides this functionality natively.ANSI SQL users
ANSI SQL users
In ANSI SQL, formatting bytes requires complex CASE statements. APL’s
format_bytes simplifies this operation.Usage
Syntax
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| value | number | Yes | The numeric value representing bytes to format. |
| precision | number | No | Number of decimal places (default: 0). |
| units | string | No | Target units (e.g., ‘KB’, ‘MB’, ‘GB’). If omitted, units are auto-selected. |
| base | number | No | Either 2 (default, 1024-based) or 10 (1000-based) for unit calculations. |
Returns
Returns a formatted string representing the byte value with appropriate units.Use case examples
- Log analysis
- OpenTelemetry traces
- Security logs
Format request duration values as human-readable sizes for better analysis of payload patterns.QueryRun in PlaygroundOutput
This query formats average request duration values by HTTP status code, making it easier to identify which status codes are associated with larger data transfers.
| status | avg_size | formatted_avg |
|---|---|---|
| 500 | 8765432 | 8.36 MB |
| 200 | 3456789 | 3.30 MB |
| 404 | 1234567 | 1.18 MB |
| 301 | 456789 | 446.08 KB |
List of related functions
- parse_bytes: Parses a formatted byte string back to a numeric value. Use this to reverse the formatting operation.
- strlen: Returns the length of a string in characters. Use this when you need character count rather than byte formatting.