.net ,Sql 四捨五入

摘要:.net 四捨五入

.net

http://msdn.microsoft.com/en-us/library/system.math.round.aspx

 

剛好這陣子在處理一些數字的問題,又重新找了相關的文件。

.net 2.0 以上支援

Math.round(0.5,0,MidpointRounding.AwayFromZero) = 1
Math.round(0.6,0,MidpointRounding.AwayFromZero) = 2

Sql

http://social.technet.microsoft.com/Forums/zh-TW/01ca0dd6-fe5b-4ec9-9949-ce3608fcebf6/sqlround?forum=sqlservermanagementzhcht

 

需要進行 ROUND() 的欄位,該欄位資料型態建議不要用 float、real,應該用 decimal、numeric

SELECT ROUND(CAST(9999.285 AS decimal(10,3)),2) -- 9999.290
SELECT ROUND(CAST(9999.285 AS float),2) -- 9999.280