todouble function (or its synonym toreal) to convert various data types to a real (floating-point) number. This is helpful when you need to normalize numeric values from different sources into decimal format for mathematical operations, comparisons, or aggregations.
You typically use todouble when working with numeric strings, integers, or other types that need to be converted to floating-point numbers for precise calculations or when decimal precision is required.
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 handles both integers and decimals. In APL, todouble specifically converts to floating-point numbers, while toint or tolong handle integers.ANSI SQL users
ANSI SQL users
In standard SQL, you use
CAST(... AS DOUBLE) or CAST(... AS REAL) to convert values to floating-point numbers. In APL, todouble and toreal are synonyms that provide a simpler way to convert to real numbers.Usage
Syntax
Parameters
| Name | Type | Description |
|---|---|---|
| value | dynamic | The value to convert to real. |
Returns
If conversion is successful, the result is a value of typereal. If conversion isn’t successful, the result is null.
Conversion behavior
Thetodouble function converts values based on their type:
- Integer: Converted to float. For example,
1becomes1.0,-1becomes-1.0. - String: Parsed as a 64-bit float using Go floating-point literal syntax, which supports scientific notation. For example,
"1e3"becomes1000.0. - Boolean:
truebecomes1.0,falsebecomes0.0 - Datetime: Converted to nanoseconds since epoch as a float
- Duration: Converted to float nanoseconds
Use case examples
- Log analysis
- OpenTelemetry traces
- Security logs
Convert string representations of numeric values to real numbers for mathematical calculations and aggregations.QueryRun in PlaygroundOutput
This example converts milliseconds to seconds using
| _time | uri | req_duration_ms | duration_seconds | is_slow |
|---|---|---|---|---|
| Jun 24, 09:28:10 | /api/users | 1500 | 1.5 | true |
todouble to ensure decimal precision in the calculation, enabling accurate time-based analysis.