double()

Converts a value to a 64-bit double-precision floating-point number.

Syntax

double(EXPR)

Parameters

EXPR
The value or expression to convert to a floating-point number.

Description

The double() function converts the argument to a 64-bit double-precision floating-point number (double) and returns it. If the argument is null, returns null. If conversion fails, also returns null.

Numeric types (integer, long, etc.) are converted directly to double. For strings, Double.parseDouble() is used for parsing. An empty string returns null. If an array or list is passed, the conversion is applied recursively to each element.

Error codes

N/A

Usage examples

To prepare the WEB_APACHE_SAMPLE table used in these examples, refer to Preparing sample data.

  1. Converting the bytes integer field to a floating-point number

    table limit=5 WEB_APACHE_SAMPLE | eval result = double(bytes) | fields bytes, result
    | # result: 2780.0, 162.0, etc.
    
  2. Converting a string to a floating-point number

    json "{'val': '3.14'}" | eval result = double(val)
    | # result: 3.14
    
  3. Non-convertible string

    json "{'val': 'abc'}" | eval result = double(val)
    | # result: null
    
  4. NULL input

    json "{'val': null}" | eval result = double(val)
    | # result: null
    

Compatibility

The double() function has been available since before Sonar 4.0.