1.round(P1, P2) 函數是四捨五入用,第一個參數是我們要被操作的數據,第二個參數是設置我們四捨五入之後小數點後顯示幾位。
2.numeric(P1, P2) 函數的2個參數,第一個表示數據長度,第二個參數表示小數點後位數。
例如:
select cast(round(23.5,2) as numeric(5,2)) --結果:23.50
select cast(round(23.555,2) as numeric(5,2)) --結果:23.56
select cast(round(234.5255,2) as numeric(5,2)) --結果:234.53
select cast(round(2345.5255,2) as numeric(5,2)) --結果:報錯了!
Arithmetic overflow error converting numeric to data type numeric.
原因是:2345.5255,整數位是4,小數位是2,加起來4+2=6,超出了numeric設置的5位,所以為了保險,可以增減numeric的參數,例如numeric(20,2)。
期待您的留言

Comments