get sql server to warn about truncation / rounding

2019-08-07 14:04发布

I am working on an ASP.NET C# accounting app and I am in the transition from using floats/doubles to using decimals to represent money.

Now I want to control when and where rounding takes place. The way I understand it, SQL server rounds decimal data types differently than C# does.

Is there some way to get SQL server (2008) to warn or fail if decimal values (or any kind of data) are getting truncated or rounded?

Thanks,

1条回答
Root(大扎)
2楼-- · 2019-08-07 14:39

Look at SET NUMERIC_ROUNDABORT and the table with SET ARITHABORT

This determines whether nothing or something happens. The something (an error or warning) depends on SET ARITHABORT. However, you get NULL for a warning.

I'd consider doing your calculations in the client code, or use a wide decimal (eg 38,20) to mitigate it

查看更多
登录 后发表回答