如何构建SQLDECIMAL数据类型,指定precision和规模的实例 [英] How to construct an instance of the SqlDecimal datatype that specifies precision and scale
问题描述
MSDN 有关于如何构建的一个新实例文档这包括指定precision和规模SQLDECIMAL数据类型,它只能设置在施工时间。
下面是工作的一个例子,但我不明白如何将值属性设置:
SQLDECIMAL的Test2 =新SQLDECIMAL(10,3,假的,新的INT [4] {2,1,0,0});
当我打印下面的调试语句,我看到了precision和尺度参数是直截了当的,但我不明白是怎么值从长度为4的整数数组确定。
?试验。precision
10
? Test.Scale
3
? Test2.Value
-4294967.298
如何在4个整数组合拳,以指定的值?有没有榜样,没有解释。
INT [4] {2,1,0,0}
=
96-127:0000 0000 0000 0000 0000 0000 0000 0000 - 0
64- 95:0000 0000 0000 0000 0000 0000 0000 0000 - 0
32- 63:0000 0000 0000 0000 0000 0000 0000 0001 - 1
00- 31:0000 0000 0000 0000 0000 0000 0000 0010 - 2
此128位二进制的值是
2 ^ 32 + 2 ^ 1 = 4294967298
由于规模为3,小数位被移动3的左边,使得它4294967.298
第三个参数来SQLDECIMAL构性是假
使它成为负值。
MSDN has documentation about how to construct a new instance of the SqlDecimal data type that includes specifying precision and scale, which can only be set at construction time.
Here's an example that works, but I don't understand how to set the value property:
SqlDecimal Test2 = new SqlDecimal(10, 3, false, new int[4] { 2, 1, 0, 0 });
When I print the following debug statements, I see that the Precision and Scale parameters are straight forward, but I don't understand how the value is determined from the integer array of length 4.
? Test.Precision
10
? Test.Scale
3
? Test2.Value
-4294967.298
How are the 4 integers "combined" to specify the value? There's no example and no explanation.
int[4] { 2, 1, 0, 0 }
=
96-127: 0000 0000 0000 0000 0000 0000 0000 0000 -- 0
64- 95: 0000 0000 0000 0000 0000 0000 0000 0000 -- 0
32- 63: 0000 0000 0000 0000 0000 0000 0000 0001 -- 1
00- 31: 0000 0000 0000 0000 0000 0000 0000 0010 -- 2
The value of this 128-bit binary is
2 ^ 32 + 2 ^ 1 = 4294967298
Because the scale is 3, the decimal place is moved 3 to the left, making it 4294967.298
And the third parameter to SqlDecimal constructure being false
makes it a negative value.
这篇关于如何构建SQLDECIMAL数据类型,指定precision和规模的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!