BigInteger Explicit Conversion (Double to BigInteger)


Defines an explicit conversion of a Double value to a BigInteger value.

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

public static explicit operator BigInteger (
	double value


Type: System.Double

The value to convert to a BigInteger.

Return Value

Type: System.Numerics.BigInteger

An object that contains the value of the value parameter.

Exception Condition

value is Double.NaN.


value is Double.PositiveInfinity.


value is Double.NegativeInfinity.

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 Double 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 Double values to BigInteger objects, and then displays the result of each conversion. Note that any fractional part of a Double value is truncated during the conversion.

double[] doubles = { Double.MinValue, -1.430955172e03, 2.410970032e05, 
                     Double.MaxValue, Double.PositiveInfinity, 
                     Double.NegativeInfinity, Double.NaN };
BigInteger number;

Console.WriteLine("{0,37} {1,37}\n", "Double", "BigInteger");

foreach (double value in doubles)
   try {
      number = (BigInteger) value;
      Console.WriteLine("{0,37} {1,37}", value, number);
   catch (OverflowException) {
      Console.WriteLine("{0,37} {1,37}", value, "OverflowException");
// The example displays the following output:
//                                Double                            BigInteger
//                -1.79769313486232E+308  -1.7976931348623157081452742373E+308
//                          -1430.955172                                 -1430
//                           241097.0032                                241097
//                 1.79769313486232E+308   1.7976931348623157081452742373E+308
//                              Infinity                     OverflowException
//                             -Infinity                     OverflowException
//                                   NaN                     OverflowException      

Universal Windows Platform
Available since 8
.NET Framework
Available since 4.0
Portable Class Library
Supported in: portable .NET platforms
Available since 4.0
Windows Phone
Available since 8.1
Return to top