Oracle 保留小数位
1、round(number[,decimals])指定位数进行四舍五入
select round(555.2355,2) from dual -- 555.24
select round(555.2355,-2) from dual --600
2、trunc(number[,decimals])指定位数不四舍五入 或者 获取特定的日期时间
select trunc(555.2355,2) from dual --555.23
select trunc(555.2355,-2) from dual --500
--其中第二个参数大小写均可
--记忆起来有一定的规律(第二个参数对应了各自的精度)
select trunc(sysdate) from dual --2020/5/18 今天的日期为2020/5/18
select trunc(sysdate,'yy') from dual --2020/1/1 返回当年第一天
select trunc(sysdate,'yyyy') from dual --2020/1/1 返回当年第一天
select trunc(sysdate, 'mm') from dual --2020/5/1 返回当月第一天.
select trunc(sysdate,'d') from dual --2020/5/17 (星期天)返回当前星期的第一天
select trunc(sysdate,'dd') from dual --2020/5/18 返回当前年月日
select trunc(sysdate, 'hh') from dual --2020/5/18 2:00:00 当前时间为17:35
select trunc(sysdate, 'mi') from dual --2020/5/18 2:36:00 TRUNC()函数没有秒的精确
3、to_char(number,’FM99990.99’) 格式化数字(四舍五入)
--数字9是占位符,数字0也是占位符(区别在于0站位时必定会显示那一位,常用于个位)
select TO_CHAR(0.2355,'FM99990.99') from dual --0.24
select TO_CHAR(0.2355,'FM99900.99') from dual --00.24
select TO_CHAR(0.2355,'99990.99') from dual --0.24 去掉FM也行
select TO_CHAR(0.2355,'99900.99') from dual --00.24 去掉FM也行