vb / c#十进制内部格式

前端之家收集整理的这篇文章主要介绍了vb / c#十进制内部格式前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
VB或C#中“十进制”值的内部格式是什么?

我不知道这对我正在做的任何事都很重要,但这是很有趣的事情之一.比如,知道有多少位以及负数如何存储可能意味着当你看到一个负数出现在你预期的正面时,你可以立刻想到,“啊,有一个溢出”而不是被深深的黑暗奥秘困惑.

您的问题的答案由 documentation提供完整的技术色彩:

The Decimal value type represents decimal numbers ranging from
positive 79,228,162,514,264,337,593,543,950,335 to negative
79,335. The Decimal value type is
appropriate for financial calculations requiring large numbers of
significant integral and fractional digits and no round-off errors.
The Decimal type does not eliminate the need for rounding. Rather,it
minimizes errors due to rounding.

A decimal number is a floating-point value that consists of a sign,a
numeric value where each digit in the value ranges from 0 to 9,and a
scaling factor that indicates the position of a floating decimal point
that separates the integral and fractional parts of the numeric value.

The binary representation of a Decimal value consists of a 1-bit sign,
a 96-bit integer number,and a scaling factor used to divide the
96-bit integer and specify what portion of it is a decimal fraction.
The scaling factor is implicitly the number 10,raised to an exponent
ranging from 0 to 28. Therefore,the binary representation of a
Decimal value is of the form,((-296 to 296) / 10(0 to 28)),where
-296-1 is equal to MinValue,and 296-1 is equal to MaxValue. For more information about the binary representation of Decimal values and an example,see the 07001 constructor and the 07002 method.

The scaling factor also preserves any trailing zeroes in a Decimal
number. Trailing zeroes do not affect the value of a Decimal number in
arithmetic or comparison operations. However,trailing zeroes can be
revealed by the ToString method if an appropriate format string is
applied.

和二进制表示,如GetBits的文档中所述:

The binary representation of a Decimal number consists of a 1-bit
sign,a 96-bit integer number,and a scaling factor used to divide the
integer number and specify what portion of it is a decimal fraction.
The scaling factor is implicitly the number 10,raised to an exponent
ranging from 0 to 28.

The return value is a four-element array of 32-bit signed integers.

The first,second,and third elements of the returned array contain
the low,middle,and high 32 bits of the 96-bit integer number.

The fourth element of the returned array contains the scale factor and
sign. It consists of the following parts:

Bits 0 to 15,the lower word,are unused and must be zero.

Bits 16 to 23 must contain an exponent between 0 and 28,which
indicates the power of 10 to divide the integer number.

Bits 24 to 30 are unused and must be zero.

Bit 31 contains the sign: 0 mean positive,and 1 means negative.

Note that the bit representation differentiates between negative and positive zero. These values are treated as being equal in all operations.

猜你在找的VB相关文章