度量快速开发平台-专业、快速的软件定制快开平台
标题: Oracle SQL语句实现数字四舍五入取整 [打印本页]
作者: 万望 时间: 2020-5-15 21:11
标题: 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
作者: 万望 时间: 2020-5-15 21:12
作者: 陈晓龙 时间: 2020-5-16 16:30
作者: 万望 时间: 2020-5-25 13:54
欢迎光临 度量快速开发平台-专业、快速的软件定制快开平台 (http://plat.delit.cn/) |
Powered by Discuz! X3.2 |