Oracle中round() 函數與trunc()函數的比較

來源:互聯網
上載者:User

Oracle中round() 函數與trunc()函數的比較,非常實用。

round(x[,y])

【功能】返回四捨五入後的值

【參數】x,y,數字型運算式,如果y不為整數則截取y整數部分,如果y>0則四捨五入為y位小數,如果y小於0則四捨五入到小數點向左第y位。

【返回】數字

【樣本】 select round(5555.6666,2.1),round(5555.6666,-2.6),round(5555.6666) from dual;

返回: 5555.67 , 5600 , 5556

【相近】trunc(x[,y]) 返回截取後的值,用法同round(x[,y]),只是不四捨五入

trunc(x[,y])

【功能】返回x按精度y截取後的值

【參數】x,y,數字型運算式,如果y不為整數則截取y整數部分,如果y>0則截取到y位小數,如果y小於0則截取到小數點向左第y位,小數前其它資料用0表示。

【返回】數字

【樣本】 select trunc(5555.66666,2.1),trunc(5555.66666,-2.6),trunc(5555.033333) from dual;

返回:5555.66 5500 5555

【相近】round(x[,y]) 返回截取後的值,用法同trunc(x[,y]),只是要做四捨五入

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.