to_double.asciidoc 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. [[esql-to_double]]
  2. === `TO_DOUBLE`
  3. Converts an input value to a double value.
  4. The input can be a single- or multi-valued field or an expression. The input
  5. type must be of a boolean, date, string or numeric type.
  6. Example:
  7. [source,esql]
  8. ----
  9. include::{esql-specs}/floats.csv-spec[tag=to_double-str]
  10. ----
  11. returns:
  12. [%header,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