Oracle PL/SQL - Convert To BINARY_FLOAT and BINARY_DOUBLE

Introduction

To force the appropriate overload, using one of these two conversion functions:

v_float_nr:= to_binary_float(numeric variable)
v_double_nr:= to_binary_double(numeric variable)

Demo

SQL>
SQL> declare-- from w w w.  jav  a 2 s . c  om
  2      v_nr binary_float;
  3  begin
  4      for i in 1..1000000 loop
  5          v_nr:=sqrt(to_binary_float(i));
  6      end loop;
  7  end;
  8  /

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.17
SQL>

The conversion from NUMBER to BINARY_FLOAT/DOUBLE is not exact.

Because NUMBER data is rounded to a decimal point and BINARY data is rounded to a binary value.

Related Topic