— Start
Oracle 提供了以下四个函数用来做四舍五入。
CEIL 向上四舍五入
FLOOR 向下四舍五入
ROUND 四舍五入
TRUNC 去掉小数
下面让我们通过例子来看看它们之间的不同。
SELECT 5.5 NUM, CEIL(5.5) CEIL, FLOOR(5.5) FLOOR, ROUND(5.5) ROUND, TRUNC(5.5, 0) TRUNC FROM DUAL
UNION ALL
SELECT 2.5 NUM, CEIL(2.5) CEIL, FLOOR(2.5) FLOOR, ROUND(2.5) ROUND, TRUNC(2.5, 0) TRUNC FROM DUAL
UNION ALL
SELECT 1.6 NUM, CEIL(1.6) CEIL, FLOOR(1.6) FLOOR, ROUND(1.6) ROUND, TRUNC(1.6, 0) TRUNC FROM DUAL
UNION ALL
SELECT 1.1 NUM, CEIL(1.1) CEIL, FLOOR(1.1) FLOOR, ROUND(1.1) ROUND, TRUNC(1.1, 0) TRUNC FROM DUAL
UNION ALL
SELECT 1 NUM, CEIL(1) CEIL, FLOOR(1) FLOOR, ROUND(1) ROUND, TRUNC(1, 0) TRUNC FROM DUAL
UNION ALL
SELECT -1 NUM, CEIL(-1) CEIL, FLOOR(-1) FLOOR, ROUND(-1) ROUND, TRUNC(-1, 0) TRUNC FROM DUAL
UNION ALL
SELECT -1.1 NUM, CEIL(-1.1) CEIL, FLOOR(-1.1) FLOOR, ROUND(-1.1) ROUND, TRUNC(-1.1, 0) TRUNC FROM DUAL
UNION ALL
SELECT -1.6 NUM, CEIL(-1.6) CEIL, FLOOR(-1.6) FLOOR, ROUND(-1.6) ROUND, TRUNC(-1.6, 0) TRUNC FROM DUAL
UNION ALL
SELECT -2.5 NUM, CEIL(-2.5) CEIL, FLOOR(-2.5) FLOOR, ROUND(-2.5) ROUND, TRUNC(-2.5, 0) TRUNC FROM DUAL
UNION ALL
SELECT -5.5 NUM, CEIL(-5.5) CEIL, FLOOR(-5.5) FLOOR, ROUND(-5.5) ROUND, TRUNC(-5.5, 0) TRUNC FROM DUAL;
结果如下:
NUM CEIL FLOOR ROUND TRUNC
5.5 6 5 6 5
2.5 3 2 3 2
1.6 2 1 2 1
1.1 2 1 1 1
1 1 1 1 1
-1 -1 -1 -1 -1
-1.1 -1 -2 -1 -1
-1.6 -1 -2 -2 -1
-2.5 -2 -3 -3 -2
-5.5 -5 -6 -6 -5
— 声明:转载请注明出处
— Last edited on 2015-07-27
— Created by ShangBo on 2015-02-23
— End
今天的文章oracle 的四舍五入,Oracle 数值四舍五入分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/24521.html