是否有舍入函数 oracle 可以舍入到特定数量的有效数字?
例如,将 1278 舍入到 1300,舍入到两位有效数字。
就在我的脑海中,可能是进一步优化的主题:)
16:54:16 SYSTEM@dwal> select to_number(to_char(1278, '9.9EEEE')) t from dual;
T
----------
1300
Elapsed: 00:00:00.01
16:54:34 SYSTEM@dwal> select to_number(to_char(.1234, '9.9EEEE')) t from dual;
T
----------
.12
Elapsed: 00:00:00.01
试试ROUND(x, d - FLOOR(LOG(10, x)) - 1)
whered
是有效位数,x
是要四舍五入的值。
例子:
SELECT
ROUND(x, d - FLOOR(LOG(10, x)) - 1)
FROM (SELECT 1278 x, 2 d FROM DUAL UNION ALL
SELECT 0.1234 x, 2 d FROM DUAL );
select round(1348,-2) from dual;