oracle 值 99999999 四舍五入

oracle value 99999999 getting rounded

我创建了以下 table:

create table ex_employee (id number(20,4));

然后我插入以下值:

insert into ex_employee values (9999999999999999.9999);
commit;

结果正在四舍五入;

10000000000000000.0000

In this link 他们解释说如果精度超过精度就会向上舍入。

我应该怎么做才能使值不四舍五入:
9999999999999999.9999

只需正确设置 numformat。在 SQL*Plus 中,您可以按 set numformat.

进行操作
SQL> set numformat 9999999999999999.9999
SQL> create table ex_employee (id number(20,4));

Table created.

SQL> insert into ex_employee values (9999999999999999.9999);

1 row created.

SQL> select id from ex_employee;

                    ID
----------------------
 9999999999999999.9999

SQL>

The result is being rounded up [to] 10000000000000000.0000

what should I do to keep the value not get rounded: 9999999999999999.9999

正如您自己注意到的,这是一个显示问题,因为您的 NUMBER(20,4) 有足够的有效数字来精确表示 base10 数字。

如果除了 Lalit 关于 "display format" 的回答之外,该行为的一个常见来源是在应用程序级别使用 IEEE 754 float/double 值来回读这些数字(resp. 7 / 15仅重要的 十进制 数字)。另外,所有的十进制数字都不能用二进制来准确表示。

如果您的宿主语言支持它,您应该"long decimal numbers"。例如,Java 有 BigDecimal. Python has Decimal.