TO_BINARY_FLOAT Function
1. Purpose
TO_BINARY_FLOAT converts text or numeric input to BINARY_FLOAT, a 32-bit single-precision binary floating-point value.
2. Function Description
TO_BINARY_FLOAT(value)
TO_BINARY_FLOAT(text_value, format_model)
| Call form | Behavior |
|---|---|
|
Parses floating-point text directly, including signs, surrounding spaces, and scientific notation |
|
Parses text using a number format model, then converts to the target precision |
|
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_float('1.2345678901234e+20') AS scientific,
sys.to_binary_float('16777217') AS rounded_value;
IvorySQL 6.0 displays 1.2345679E+020 and 1.6777216E+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_float('1,234.5', '9,999.9') AS grouped_value,
sys.to_binary_float(' 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_float(42::sys.number) AS from_number,
sys.to_binary_float(42::sys.binary_double) AS from_binary;
SELECT sys.to_binary_float('NaN') AS nan_value,
sys.to_binary_float('inf') AS positive_infinity,
sys.to_binary_float('-Infinity') AS negative_infinity;
SELECT sys.to_binary_float(NULL::text) IS NULL AS null_input,
sys.to_binary_float('123', '') IS NULL AS empty_format,
sys.to_binary_float('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.