Mono Class Library: System.Decimal Overview | Members

System.Decimal Constructor

Constructs and initializes a new decimal value.

public Decimal (int[] bits)

Parameters

bits
An array of four int containing an unspecified 128-bit representation of a decimal in its raw form.

Exceptions

TypeReason
ArgumentNullExceptionbits is a null reference.
ArgumentExceptionbits does not contain four elements.

Remarks

This constructor initializes the new decimal to the value represented by the elements of bits .

Note: A numeric value can have several possible binary representations; they are numerically equal but have different scales. Also, the bit representation differentiates between -0, 0.00, and 0; these are all treated as 0 in operations, and any zero result will have a sign of 0.

The format of bits is the same as that returned by decimal.GetBits(System.Decimal) .

Example

The following example demonstrates using the decimal (Int32 []) constructor.

C# Example

using System;
class ConstructDecimal {
 public static void Main() {
 int negativeBitValue = unchecked ((int)0x80000000);
 int [] parts0 = {0,0,0,0}; //Positive Zero.
 int [] parts1 = {1,0,0,0};
 int [] parts2 = {0,1,0,0};
 int [] parts3 = {0,0,1,0};
 int [] parts4 = {0,0,0,negativeBitValue}; // Negative zero.
 int [] parts5 = {1,1,1,0};
 int [] partsMaxValue = {-1,-1,-1,0};
 int [] partsMinValue = {-1,-1,-1,negativeBitValue};

 decimal d = new Decimal(parts0);
 Console.WriteLine("{{0,0,0,0}} = {0}",d);
 d = new Decimal(parts1);
 Console.WriteLine("{{1,0,0,0}} = {0}",d);
 d = new Decimal(parts2);
 Console.WriteLine("{{0,1,0,0}} = {0}",d);
 d = new Decimal(parts3);
 Console.WriteLine("{{0,0,1,0}} = {0}",d);
 d = new Decimal(parts4);
 Console.WriteLine("{{0,0,0,{0}}} = {1}",parts4[3],d);
 d = new Decimal(parts5);
 Console.WriteLine("{{1,1,1,0}} = {0}",d);
 d = new Decimal(partsMaxValue );
 Console.WriteLine("{{-1,-1,-1,0}} = {0}",d);
 d = new Decimal(partsMinValue);
 Console.WriteLine("{{-1,-1,-1,{0}}} = {1}",partsMinValue [3],d);
 }
}

The output is

{0,0,0,0} = 0
{1,0,0,0} = 1
{0,1,0,0} = 4294967296
{0,0,1,0} = 18446744073709551616
{0,0,0,-2147483648} = 0
{1,1,1,0} = 18446744078004518913
{-1,-1,-1,0} = 79228162514264337593543950335
{-1,-1,-1,-2147483648} = -79228162514264337593543950335

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0