VB / C#十进制内部格式 [英] vb/c# decimal internal format

查看:170
本文介绍了VB / C#十进制内部格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是在VB或者C#中的十进制值?

What is the internal format of a "decimal" value in VB or C#?

我不知道,这关系到什么,我马上做,但它的那些东西,是很好的了解的。像,知道有多少位以及如何负数存储可能意味着,当你看到一个负数显示出来,你期待一个积极的,你可以马上想到:啊,有一个溢出,而不是莫名其妙深暗色的奥秘

I don't know that this matters to anything I'm doing immediately, but it's one of those things that's good to know. Like, knowing how many bits and how negative numbers are stored can mean that when you see a negative number show up where you expected a positive, you can instantly think, "Ah, there was an overflow" rather than being baffled by deep dark mysteries.

推荐答案

在回答你的问题是通过的文档

The answer to your question is provided in full technicolor by the documentation:

十进制值类型重新presents十进制数字,从   积极79,228,162,514,264,337,593,543,950,335负   79,228,162,514,264,337,593,543,950,335。十进制值类型是   适合于金融计算需要大量的   显著整数和小数位,没有舍入误差。   十进制类型不消除对四舍五入。相反,它   四舍五入最大限度地减少由于错误的。

The Decimal value type represents decimal numbers ranging from positive 79,228,162,514,264,337,593,543,950,335 to negative 79,228,162,514,264,337,593,543,950,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.

一个十进制数是由一个符号的一个浮点值,一   数字值,其中在所述值的每个数字范围从0到9,和一个   缩放因子,指示浮动小数点的位置   分隔数值的整数和小数部分。

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.

十进制值的二进制重新presentation由1位标志,   一个96位整数,用来划分的比例因子   96位整数,并指定哪些它部分是一个小数。   缩放因子是隐含数目为10,升温至指数   范围从0到28。因此,二进制重新$ P $的psentation   十进制值的形式为,((-2 96 2 96 )/ 10 (0〜28 )),其中,   -2 96 -1等于MINVALUE,和2 96 -1等于MaxValue的。关于十进制值的二进制再presentation和示例的详细信息,请参阅的十进制(的Int32 [])构造和 GetBits 方法。

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 Decimal(Int32[]) constructor and the GetBits method.

缩放系数也preserves在小数任何尾随零   数。尾随零不影响十进制数的值   算术或比较操作。但是,尾随零可能   通过ToString方法显示,如果以适当的格式字符串   应用。

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.

和二进制再presentation,为的 GetBits

And the binary representation, as described in the documentation for GetBits:

十进制数的二进制重新presentation由1位的   签,96位整数,用来划分的比例因子   整数,并指定哪些部分是一个小数。   缩放因子是隐含数目为10,升温至指数   范围从0到28。

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.

返回值是32位有符号整数的四元素的数组。

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

第一,第二和第三返回的数组的元素包含   低,中,和高32位的96位的整数。

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:

0〜15位,低字,未使用的,必须是零。

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

位16至23必须包含介于0和28指数,其   表示10的幂来划分整数。

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

24位到第30的未使用的,必须是零。

Bits 24 to 30 are unused and must be zero.

第31位包含符号:0的意思是积极的,1表示负

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

请注意那些重新presentation位阴性和区分   正零。这些值被视为相等的所有   操作。

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

这篇关于VB / C#十进制内部格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆