Why SELECT 123456.123456789123456 FROM Dual; returns 123456.123457?

Why SELECT 123456.123456789123456 FROM Dual;returns 123456.123457?

How to increase this accuracy?

I ask about this because I am summing up the value values ​​defined as NUMBER(38,20), and I may notice that errors accumulate, but since these numbers represent money, rounding is not allowed.

This is not only the tool that I use that rounds the display of the number, but the number itself is rounded, because the reports also contain accumulated errors.

+3
source share
2 answers

Well, that is not so. But, as you say, a tool (e.g. SQL Plus) that displays the result can round it to display:

SQL> SELECT 123456.123456789123456 n from dual;

         N
----------
123456.123

SQL> column n format 9999999999.99999999999999999999999999999
SQL> SELECT 123456.123456789123456 n from dual;

                                        N
-----------------------------------------
     123456.12345678912345600000000000000

SQL Plus , .

, , -, , , , , SQL /.

+6

, (38,20) :

SQL> create table test (x number(38,20));

Table created.

SQL> insert into test values (123456.123456789123456);

1 row created.

SQL> commit;

Commit complete.

SQL> select x - 123456.123456789123456 from test;

X-123456.123456789123456
------------------------
               0

, .

+2

Source: https://habr.com/ru/post/1754433/


All Articles