TO_BINARY_DOUBLE Function

1. Purpose

TO_BINARY_DOUBLE converts text or numeric input to BINARY_DOUBLE, a 64-bit double-precision binary floating-point value.

2. Function Description

TO_BINARY_DOUBLE(value)
TO_BINARY_DOUBLE(text_value, format_model)
Call form Behavior

TO_BINARY_DOUBLE(text_value)

Parses floating-point text directly, including signs, surrounding spaces, and scientific notation

TO_BINARY_DOUBLE(text_value, format_model)

Parses text using a number format model, then converts to the target precision

TO_BINARY_DOUBLE(value)

Accepts NUMBER, BINARY_FLOAT, and BINARY_DOUBLE values. A value already of the target type is returned directly

The function returns NULL when any argument is NULL or the format model is empty. Use the one-argument form to parse text directly.

3. Examples

Run the examples in an Oracle compatibility session with the ivorysql_ora extension installed.

SHOW ivorysql.compatible_mode;

Confirm that the result is oracle.

3.1. Parse Text Directly

SELECT sys.to_binary_double('1.2345678901234e+200') AS scientific,
       sys.to_binary_double('16777217') AS rounded_value;

IvorySQL 6.0 displays 1.2345678901234E+200 and 1.6777217E+007, respectively. Binary floating-point values are stored at the target type’s precision.

3.2. Parse With a Format Model

SELECT sys.to_binary_double('1,234.5', '9,999.9') AS grouped_value,
       sys.to_binary_double('  1234.5', '9999.9') AS padded_value;

Both columns have the numeric value 1234.5. Leading spaces in the second input do not consume digit positions in the model.

3.3. Convert Numeric and Special Values

SELECT sys.to_binary_double(42::sys.number) AS from_number,
       sys.to_binary_double(42::sys.binary_float) AS from_binary;

SELECT sys.to_binary_double('NaN') AS nan_value,
       sys.to_binary_double('inf') AS positive_infinity,
       sys.to_binary_double('-Infinity') AS negative_infinity;

SELECT sys.to_binary_double(NULL::text) IS NULL AS null_input,
       sys.to_binary_double('123', '') IS NULL AS empty_format,
       sys.to_binary_double('123', NULL::text) IS NULL AS null_format;

Both columns in the first query have the value 42. The second query displays Nan, Inf, and -Inf. All three checks in the last query return true.

4. Usage Notes

The one-argument text form follows the BINARY_DOUBLE input rules. Invalid floating-point text raises an error. Finite values outside the representable range can become infinity, and very small values can round to zero. Use NUMBER when decimal precision is required.