Oracle SQL语句实现数字四舍五入取整
取整(向下取整):
代码如下:
select floor(5.534) from dual; select trunc(5.534) from dual;
上面两种用法都可以对数字5.534向下取整,结果为5.
如果要向上取整 ,得到结果为6,则应该用ceil
代码如下:
select ceil(5.534) from dual;
四舍五入:
代码如下:
SELECT round(5.534) FROM dual; SELECT round(5.534,0) FROM dual; SELECT round(5.534,1) FROM dual; SELECT round(5.534,2) FROM dual;
结果分别为 6, 6, 5.5, 5.53
保留N位小数(不四舍五入):
代码如下:
select trunc(5.534,0) from dual; select trunc(5.534,1) from dual; select trunc(5.534,2) from dual;
结果分别是 5,5.5,5.53,其中保留0位小数就相当于直接取整了。
数字格式化:
代码如下:
select to_char(12345.123,'99999999.9999') from dual;
结果为12345.123
代码如下:
select to_char(12345.123,'99999999.9900') from dual;
小数后第三第四为不足补0,结果为12345.1230
代码如下:
select to_char(0.123,'99999999.9900') from dual; select to_char(0.123,'99999990.9900') from dual;
结果分别为 .123, 0.123
相关推荐
beichenyx 2020-06-02
wbczyh 2020-03-28
SJCHEN 2020-02-01
Yasin 2019-12-27
wuxiaosi0 2019-12-16
willowwgx 2019-10-26
socket 2019-04-11
weialemon 2019-03-27
Yellowpython 2019-07-01
jling 2019-07-01
xiaochuachua 2014-02-26
bangrenzhuce 2019-06-25
stoutT 2010-05-18
wuqingyong 2012-12-26
jingxiao 2019-06-21
梦想的翅膀 2012-03-09
花花的技术 2011-11-22