What is a good mapping of .NET decimal to SQL Server decimal?

前端 未结 6 1269
清酒与你
清酒与你 2021-01-03 18:08

I am having to interface some C# code with SQL Server and I want to have exactly as much precision when storing a value in the database as I do with my C# code. I use one of

6条回答
  •  花落未央
    2021-01-03 18:15

    The short answer is that C# decimal is a 128 bit floating point precision number and it does not have an exact equivalent in Sql Server.

    May be in a future Sql Server version, Microsoft will match both its products and support a straight forward [clr / c# decimal equivalent] of 128 bit floating point precision number, to directly persist on its Database Server.

    I had this analysis problem when dealing with very large and very small quantities. In my case, all comparing quantities within my solutions are inside the 64 bit range that [c# double / sql float] can handle. So, I've chosen to use [c# double / sql float] when dealing with quantities, and [c# decimal / sql money] when dealing with the financial part of my solutions.

提交回复
热议问题