sql中的四舍五入通常會有round 和cast( …… as decimal())兩種方式:
個人建議使用cast 方式:
方式1-round
經過試驗,同樣都可以做到四舍五入,但round如下實例1會報錯,
實例1:select round(0.996123,2) 報錯:將 expression 轉換為數據類型 numeric 時出現算術溢出錯誤。
實例2:select round(0.99432,2) 結果為 0.99000
方式2-cast
cast四舍五入:
SELECT CAST('123.456' as decimal(38, 2)) ===>123.46 SELECT CAST(0.996123 AS DECIMAL(38,2)) 結果為 1.00 SELECT CAST('123.456' as dec(38, 2)) ===>123.46