Oracle SQL语句实现数字四舍五入取整
取整(向下取整):
selectfloor(5.534)fromdual; selecttrunc(5.534)fromdual;
上面两种用法都可以对数字5.534向下取整,结果为5.
如果要向上取整,得到结果为6,则应该用ceil
selectceil(5.534)fromdual;
四舍五入:
SELECTround(5.534)FROMdual; SELECTround(5.534,0)FROMdual; SELECTround(5.534,1)FROMdual; SELECTround(5.534,2)FROMdual;
结果分别为6, 6, 5.5, 5.53
保留N位小数(不四舍五入):
selecttrunc(5.534,0)fromdual; selecttrunc(5.534,1)fromdual; selecttrunc(5.534,2)fromdual;
结果分别是5,5.5,5.53,其中保留0位小数就相当于直接取整了。
数字格式化:
selectto_char(12345.123,'99999999.9999')fromdual;
结果为12345.123
selectto_char(12345.123,'99999999.9900')fromdual;
小数后第三第四为不足补0,结果为12345.1230
selectto_char(0.123,'99999999.9900')fromdual; selectto_char(0.123,'99999990.9900')fromdual;
结果分别为.123,0.123
以上就是毛票票的小编为大家整理的Oracle中对数字常用的操作,需要的小伙伴可以参考一下。