문제

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.

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top