toint function (or its synonym tolong) to convert various data types to an integer (signed 64-bit) value. This is helpful when you need to normalize numeric values from different sources into integer format for mathematical operations, comparisons, or when decimal precision isn’t required.
You typically use toint when working with numeric strings, floating-point numbers, or other types that need to be converted to integers for whole-number calculations or when working with integer-based identifiers.
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, you use
tonumber to convert values to numbers, which can be integers or decimals. In APL, toint specifically converts to integers, truncating decimal values.ANSI SQL users
ANSI SQL users
In standard SQL, you use
CAST(... AS INT) or CAST(... AS INTEGER) to convert values to integers. In APL, toint provides a simpler way to convert to integer values.Usage
Syntax
Parameters
| Name | Type | Description |
|---|---|---|
| value | dynamic | The value to convert to integer. |
Returns
If the conversion is successful, the result is an integer. If the conversion isn’t successful, the result isnull.
Conversion behavior
Thetoint function converts values based on their type:
- Integer: Returns the value unchanged.
- Float: Truncates to integer.
- Boolean:
truebecomes1,falsebecomes0. - Datetime: Converts to nanoseconds since epoch as an integer.
- Duration: Converts to integer nanoseconds.
- String: Parses as a strict integer format (
"+<integer>"or"-<integer>"). Hex values and other formats aren’t supported.
Use case example
Convert string representations of HTTP status codes to integers for numeric comparisons and filtering. Query| _time | uri | status | status_int | is_error |
|---|---|---|---|---|
| Jun 24, 09:28:10 | /api/users | 404 | 404 | true |