Behind the scenes, what's happening with decimal value type in C#/.NET?

后端 未结 6 1325
囚心锁ツ
囚心锁ツ 2020-12-30 02:18

How is the decimal type implemented?

Update

  • It\'s a 128-bit value type (16 bytes)
  • 1 sign bit
  • 96 bits (1
6条回答
  •  离开以前
    2020-12-30 02:36

    From "CLR via C#" 3rd Edition by J.Richter:

    A 128-bit high-precision floating-point value commonly used for financial calculations in which rounding errors can’t be tolerated. Of the 128 bits, 1 bit represents the sign of the value, 96 bits represent the value itself, and 8 bits represent the power of 10 to divide the 96-bit value by (can be anywhere from 0 to 28). The remaining bits are unused.

提交回复
热议问题