This documentation is archived and is not being maintained.

BigInteger.Parse Method (String)

Converts the string representation of a number to its BigInteger equivalent.

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

public static BigInteger Parse(
	string value


Type: System.String
A string that contains the number to convert.

Return Value

Type: System.Numerics.BigInteger
A value that is equivalent to the number specified in the value parameter.


value is null.


value is not in the correct format.

The value parameter should be the string representation of a number in the following form.


Elements in square brackets ([ and ]) are optional. The following table describes each element.




Optional white space.


An optional sign. Valid sign characters are determined by the NumberFormatInfo.NegativeSign and NumberFormatInfo.PositiveSign properties of the current culture.


A sequence of digits ranging from 0 to 9. Any leading zeros are ignored.


The string specified by the value parameter is interpreted by using the NumberStyles.Integer style. It cannot contain any group separators or decimal separator, and it cannot have a decimal portion.

The value parameter is parsed by using the formatting information in a System.Globalization.NumberFormatInfo object that is initialized for the current system culture. For more information, see NumberFormatInfo.CurrentInfo. To parse a string by using the formatting information of a specific culture, use the Parse(String, IFormatProvider) method.

Important noteImportant

If you use the Parse method to round-trip the string representation of a BigInteger value that was output by the ToString method, you should use the BigInteger.ToString(String) method with the "R" format specifier to generate the string representation of the BigInteger value. Otherwise, the string representation of the BigInteger preserves only the 50 most significant digits of the original value, and data may be lost when you use the Parse method to restore the BigInteger value.

The following example uses the Parse(String) method to instantiate two BigInteger objects. It multiplies each object by another number and then calls the Compare method to determine the relationship between the two values.

string stringToParse = String.Empty;
   // Parse two strings.
   string string1, string2;
   string1 = "12347534159895123";
   string2 = "987654321357159852";
   stringToParse = string1;
   BigInteger number1 = BigInteger.Parse(stringToParse);
   Console.WriteLine("Converted '{0}' to {1:N0}.", stringToParse, number1);        
   stringToParse = string2;
   BigInteger number2 = BigInteger.Parse(stringToParse);
   Console.WriteLine("Converted '{0}' to {1:N0}.", stringToParse, number2);
   // Perform arithmetic operations on the two numbers.
   number1 *= 3;
   number2 *= 2;
   // Compare the numbers.
   int result = BigInteger.Compare(number1, number2);
   switch (result)
      case -1:
         Console.WriteLine("{0} is greater than {1}.", number2, number1);
      case 0:
         Console.WriteLine("{0} is equal to {1}.", number1, number2);
      case 1:
         Console.WriteLine("{0} is greater than {1}.", number1, number2);
catch (FormatException)
   Console.WriteLine("Unable to parse {0}.", stringToParse);
// The example displays the following output:
//    Converted '12347534159895123' to 12,347,534,159,895,123.
//    Converted '987654321357159852' to 987,654,321,357,159,852.
//    1975308642714319704 is greater than 37042602479685369.      

.NET Framework

Supported in: 4

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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