Export (0) Print
Expand All

BigInteger Explicit Conversion (Decimal to BigInteger)

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

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

public static explicit operator BigInteger (
	decimal value


Type: System.Decimal

The value to convert to a BigInteger.

Return Value

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

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

The overloads of the Explicit 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.

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.

decimal[] decimals = { Decimal.MinValue, -15632.991m, 9029321.12m, 
                       Decimal.MaxValue };
BigInteger number; 

Console.WriteLine("{0,35} {1,35}\n", "Decimal", "BigInteger");

foreach (decimal value in decimals)
   number = (BigInteger) value;
   Console.WriteLine("{0,35} {1,35}", value, number);
// The example displays the following output: 
//                          Decimal                          BigInteger 
//    -79228162514264337593543950335      -79228162514264337593543950335 
//                       -15632.991                              -15632 
//                       9029321.12                             9029321 
//    79228162514264337593543950335       79228162514264337593543950335

.NET Framework

Supported in: 4.6, 4.5, 4

.NET Framework Client Profile

Supported in: 4

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

Supported in: Windows Phone 8.1

Windows Phone 8.1, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft