用oracle sql对数字进行操作: 取上取整.向下取整.保留N位小数.四舍五入.数字格式化 取整(向下取整): 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; ) FROM dua
SELECT round(52.45, 0) AS round4, round(52.54, 0) AS round5, round(52.45, 1) AS round41, round(52.54, 1) AS round51, floor(52.4) AS floor4, floor(52.5) AS floor5, ceiling(52.4) AS ceiling4, ceiling(52.5) AS ceiling5 round是四舍五入 floor是向下取整 ceiling 是向上取
用oracle sql对数字进行操作: 取上取整.向下取整.保留N位小数.四舍五入.数字格式化 取整(向下取整): 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; ) FROM dua
向上取整函数:Math.ceil(double a); 向下取整函数:Math.floor(double a); 需要注意的是:取整是对小数的取整,由于java自动转型机制,两个整数的运算结果依然是整数(算是向下取整),那么再转型就没效果了. 如果需要向上取整的话,一定要保正运算的结果是小数,即参与运算的至少有一个小数,这样运算的结果也会是小数(自动转型机制): 向上取整演示: int a = 35; int b = 12; System.out.println("a/b="+a/b)