Question

I've been playing around with Numerics and the c# 128-bit counterpart decimal and noticed some differences. For one, C# decimal is 128-bit, while SQL numeric occupies an extra byte.

What I was wondering is: what would be the 'correct' (fast) SQL compliant way to implement a Numeric/Decimal in C# (just as an 'academic question')?

Oh and to make the question a bit harder:

  • Of course I want the data structure to occupy as little bytes as possible.
  • Like the normal 'decimal' in C#, I want to be able to add, subtract, divide and multiply.

Because a numeric with 17 bytes is the hardest, this is the one that really interests me. The other precisions are just variations on it that probably require another struct.

Was it helpful?

Solution

System.Data.SqlTypes.SqlDecimal already offers this. It offers the arithmetic as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top