Aracılığıyla paylaş


BigInteger Constructor (Decimal)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Initializes a new instance of the BigInteger structure using a Decimal value.

Namespace:  System.Numerics
Assembly:  System.Numerics (in System.Numerics.dll)

Syntax

'Declaration
Public Sub New ( _
    value As Decimal _
)
public BigInteger(
    decimal value
)

Parameters

Remarks

The result of calling this constructor is identical to explicitly assigning a Decimal value to a BigInteger variable.

Calling this constructor can cause data loss; any fractional part of value is truncated when instantiating a BigInteger object.

Examples

The following example illustrates the use of the BigInteger(Decimal) constructor to instantiate a BigInteger object. It defines an array of Decimal values, and then passes each value to the BigInteger(Decimal) constructor. Note that the Decimal value is truncated instead of rounded when it is assigned to the BigInteger object.

Dim decimalValues() As Decimal = {-1790.533D, -15.1514D, 18903.79D, 9180098.003D}
For Each decimalValue As Decimal In decimalValues
   Dim number As New BigInteger(decimalValue)
   outputBlock.Text += String.Format("Instantiated BigInteger value {0} from the Decimal value {1}.", 
                     number, decimalValue) + vbCrLf
Next
' The example displays the following output:
'    Instantiated BigInteger value -1790 from the Decimal value -1790.533.
'    Instantiated BigInteger value -15 from the Decimal value -15.1514.
'    Instantiated BigInteger value 18903 from the Decimal value 18903.79.
'    Instantiated BigInteger value 9180098 from the Decimal value 9180098.003.
decimal[] decimalValues = { -1790.533m, -15.1514m, 18903.79m, 9180098.003m };
foreach (decimal decimalValue in decimalValues)
{
   BigInteger number = new BigInteger(decimalValue);
   outputBlock.Text += String.Format("Instantiated BigInteger value {0} from the Decimal value {1}.",
                     number, decimalValue) + "\n";
}
// The example displays the following output:
//    Instantiated BigInteger value -1790 from the Decimal value -1790.533.
//    Instantiated BigInteger value -15 from the Decimal value -15.1514.
//    Instantiated BigInteger value 18903 from the Decimal value 18903.79.
//    Instantiated BigInteger value 9180098 from the Decimal value 9180098.003.

Version Information

Silverlight

Supported in: 5, 4

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.