1、trunc() 函數
- trunc 返回處理后的數值,其工作機制與 round() 函數極為類似,只是該函數不對指定小數前或后的部分做相應的舍入選擇處理,而統統截取。
- 其具體的語法格式:
TRUNC(number[,decimals])
- 其中: number 待處理的數值
- decimals 指明需保留小數點后面的位數。可選項,忽略它則截取所有的小數部分。
select trunc(123.11)from dual; select trunc(123.11,2)from dual; select trunc(123.11,-1)from dual;
- 注意:第二個參數可以為負數,表示小數點左邊指定位數后面的部分截去,即均以 0。與取整類似,比如參數為 1 即取到十分位,如果為 -1,則取整到十位,以此類推;如果所設置的參數為負數,且負數的位數大於或等於整數的字節數的話,則返回為 0。如:trunc(5.122,-3)=0。
2、round()函數(四舍五入)
- 傳回一個數值,該數值是按照指定的小數位元數據進行四舍五入運算的結果。
- 格式如下:
ROUND(number,[decimal_places])
- 參數解釋:
- number:欲處理的數值
- decimal_places:四舍五入,小數取幾位(預設為0)
select round(123.456,0) from dual; //123 select round(123.456,1) from dual; //123.5 select round(123.456,2) from dual; //123.46
3、ceil() 函數和 loor() 函數
- ceil(n) 取大於等於數值 n 的最小整數;
- floor(n) 取小於等於數值 n 的最小整數;