是否有一个舍入函数oracle来舍入到特定的有效数字位数?例如,将1278四舍五入到1300,四舍五入到两位有效数字。
w8biq8rn1#
刚从我的头顶上掉下来,可能是一个有待进一步优化的主题:)
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
hgtggwj02#
尝试ROUND(x, d - FLOOR(LOG(10, x)) - 1),其中d是有效数字的位数,x是要舍入的值。示例:
ROUND(x, d - FLOOR(LOG(10, x)) - 1)
d
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 );
omvjsjqw3#
select round(1348,-2) from dual;
rekjcdws4#
或者只使用:to_number(to_char(<your_number>,'0.0EEEE'),'0.0EEEE')
4条答案
按热度按时间w8biq8rn1#
刚从我的头顶上掉下来,可能是一个有待进一步优化的主题:)
hgtggwj02#
尝试
ROUND(x, d - FLOOR(LOG(10, x)) - 1)
,其中d
是有效数字的位数,x
是要舍入的值。示例:
omvjsjqw3#
rekjcdws4#
或者只使用:to_number(to_char(<your_number>,'0.0EEEE'),'0.0EEEE')