BigInteger Constructor (Double)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Initializes a new instance of the BigInteger structure using a double-precision floating-point value.

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

public BigInteger(
	double value


Type: System.Double

A double-precision floating-point value.

Exception Condition

The value of value is Double.NaN.


The value of value is Double.NegativeInfinity.


The value of value is Double.PositiveInfinity.

Any fractional part of the value parameter is truncated when instantiating a BigInteger object.

Because of the lack of precision of the Double data type, calling this constructor can cause data loss.

The BigInteger value that results from calling this constructor is identical to the value that results from explicitly assigning a Double value to a BigInteger.

The following example illustrates the use of the BigInteger(Double) constructor to instantiate a BigInteger object. It also illustrates the loss of precision that may occur when you use the Double data type. A Double is assigned a large value, which is then assigned to a BigInteger object. As the output shows, this assignment involves a loss of precision. Both values are then incremented by one. The output shows that the BigInteger object reflects the changed value, whereas the Double object does not.

// Create a BigInteger from a large double value.
double doubleValue = -6e20;
BigInteger bigIntValue = new BigInteger(doubleValue);
Console.WriteLine("Original Double value: {0:N0}", doubleValue);
Console.WriteLine("Original BigInteger value: {0:N0}", bigIntValue);
// Increment and then display both values.
bigIntValue += BigInteger.One;
Console.WriteLine("Incremented Double value: {0:N0}", doubleValue);
Console.WriteLine("Incremented BigInteger value: {0:N0}", bigIntValue);
// The example displays the following output:
//    Original Double value: -600,000,000,000,000,000,000
//    Original BigInteger value: -600,000,000,000,000,000,000
//    Incremented Double value: -600,000,000,000,000,000,000
//    Incremented BigInteger value: -599,999,999,999,999,999,999

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