Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Help me understand floating point number behavior

chuckersOct 12 2009 — edited Oct 12 2009
We transferred some data from MSAccess into a table, where a particular field "VOLUME", is specified as a floating point number in Oracle, with just NUMBER as the datatype
SQL> desc RST
 Name                  Null?    Type
 --------------------- -------- ------------
 PK                    NOT NULL NUMBER(10)
 ...
 VOLUME                         NUMBER
 ...
SQL> SELECT L.VOLUME
  2  FROM RST L
  3  Where LNO = '09-A308';

    VOLUME
----------
      14.7
But in our Oracle Forms application this number is showing up with a value of 14.699999999999999. In looking at the MSAccess table, the value shows up there as 14.7.

In trying to figure out what was going on, I tried pushing the value into a datatype with ample room for precision and I got the following:
SQL> declare
  2    cursor csr is SELECT L.VOLUME
  3                  FROM RST L
  4                  Where LAB_NO = '09-A308';
  5                    
  6      num number;  
  7      num2 number(20,10);
  8  begin
  9  
 10    for row in csr
 11    loop
 12      num := row.volume;
 13      num2 := row.volume;
 14      dbms_output.put_line(to_char(row.volume)||' '
                         ||to_char(num)||' '||to_char(num2));
 15    end loop;
 16  
 17  end;
 18  /

14.699999999999999 14.699999999999999 14.7

PL/SQL procedure successfully completed.
It's like there's some rounding going on for the float datatype at some level... but the value is also being stored as a value differently from that which was entered.

I tried looking up a description for this behavior in the documentation, but nothing's made sense so far. Anyone have a link to a description of this behavior?

Thanks,
--=Chuck
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 9 2009
Added on Oct 12 2009
2 comments
602 views