1.round() 函數是四舍五入用,第一個參數是我們要被操作的數據,第二個參數是設置我們四舍五入之后小數點后顯示幾位。
2.numeric 函數的2個參數,第一個表示數據長度,第二個參數表示小數點后位數。
例如:
select cast(round(12.5,2) as numeric(5,2)) 結果:12.50
select cast(round(12.555,2) as numeric(5,2)) 結果:12.56
select cast(round(122.5255,2) as numeric(5,2)) 結果:122.53
select cast(round(1222.5255,2) as numeric(5,2)) 結果:報錯了! 原因是:1222.5255,整數位是4,小數位是2,加起來4+2=6,超出了numeric設置的5位,所以為了保險,可以增減numeric的參數,例如numeric(20,2)。