Aracılığıyla paylaş


BigInteger Explicit Conversion (Double to BigInteger)

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

Defines an explicit conversion of a Decimal object to a BigInteger value.

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

Syntax

'Declaration
Public Shared Narrowing Operator CType ( _
    value As Double _
) As BigInteger
public static explicit operator BigInteger (
    double value
)

Parameters

Return Value

Type: System.Numerics.BigInteger
An object that contains the value of the value parameter.

Remarks

Any fractional part of the value parameter is truncated before conversion.

The overloads of the Explicit(Decimal to BigInteger) method define the types to which or from which a BigInteger object can be converted. Because the conversion from Decimal to BigInteger can involve truncating any fractional part of value, language compilers do not perform this conversion automatically. Instead, they perform the conversion only if a casting operator (in C#) or a conversion function (such as CType in Visual Basic) is used. Otherwise, they display a compiler error.

Examples

The following example converts the individual elements in an array of Decimal values to BigInteger objects, and then displays the result of each conversion. Note that any fractional part of a Decimal value is truncated during the conversion.

' Explicit Decimal to BigInteger conversion
Dim decimals() As Decimal = { Decimal.MinValue, -15632.991d, 9029321.12d, 
                              Decimal.MaxValue }
Dim number As BigInteger

outputBlock.Text += String.Format("{0,35} {1,35}", "Decimal", "BigInteger") & vbCrLf
outputBlock.Text &= vbCrLf
For Each value As Decimal In decimals
   number = CType(value, BigInteger)
   outputBlock.Text += String.Format("{0,35} {1,35}", 
                     value, number) + vbCrLf
Next
' The example displays the following output:
'
'                          Decimal                          BigInteger
'    
'    -79228162514264337593543950335      -79228162514264337593543950335
'                       -15632.991                              -15632
'                       9029321.12                             9029321
'    79228162514264337593543950335       79228162514264337593543950335
decimal[] decimals = { Decimal.MinValue, -15632.991m, 9029321.12m, 
                       Decimal.MaxValue };
BigInteger number;

outputBlock.Text += String.Format("{0,35} {1,35}\n", "Decimal", "BigInteger") + "\n";

foreach (decimal value in decimals)
{
   number = (BigInteger)value;
   outputBlock.Text += String.Format("{0,35} {1,35}", value, number) + "\n";
}
// The example displays the following output:
//
//                          Decimal                          BigInteger
//    
//    -79228162514264337593543950335      -79228162514264337593543950335
//                       -15632.991                              -15632
//                       9029321.12                             9029321
//    79228162514264337593543950335       79228162514264337593543950335

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.