to_double.asciidoc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. [discrete]
  2. [[esql-to_double]]
  3. === `TO_DOUBLE`
  4. Converts an input value to a double value.
  5. The input can be a single- or multi-valued field or an expression. The input
  6. type must be of a boolean, date, string or numeric type.
  7. Example:
  8. [source.merge.styled,esql]
  9. ----
  10. include::{esql-specs}/floats.csv-spec[tag=to_double-str]
  11. ----
  12. [%header.monospaced.styled,format=dsv,separator=|]
  13. |===
  14. include::{esql-specs}/floats.csv-spec[tag=to_double-str-result]
  15. |===
  16. Note that in this example, the last conversion of the string isn't
  17. possible. When this happens, the result is a *null* value. In this case a
  18. _Warning_ header is added to the response. The header will provide information
  19. on the source of the failure:
  20. `"Line 1:115: evaluation of [TO_DOUBLE(str2)] failed, treating result as null. Only first 20 failures recorded."`
  21. A following header will contain the failure reason and the offending value:
  22. `"java.lang.NumberFormatException: For input string: \"foo\""`
  23. If the input parameter is of a date type, its value will be interpreted as
  24. milliseconds since the https://en.wikipedia.org/wiki/Unix_time[Unix epoch],
  25. converted to double.
  26. Boolean *true* will be converted to double *1.0*, *false* to *0.0*.
  27. Alias: TO_DBL