BigInteger.ToString Method

Converts the numeric value of the current BigInteger object to its equivalent string representation.

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

public override string ToString()

Return Value

Type: System.String
The string representation of the current BigInteger value.

The return value is formatted using the general format specifier ("G"). The string representation of the BigInteger value includes a negative sign if its value is negative, and a sequence of digits ranging from 0 to 9 without leading zeros. The negative sign is defined by the NumberFormatInfo object for the current culture.

The ToString() method supports 50 decimal digits of precision. That is, if the BigInteger value has more than 50 digits, only the 50 most significant digits are preserved in the output string; all other digits are replaced with zeros.

To define the formatting of the integer value's string representation, call the ToString(String) method. To define the culture whose formatting is used in the integer value's string representation, call the ToString(IFormatProvider) method. To define both the format specifier and culture used in creating the string representation of an integer value, call the ToString(String, IFormatProvider) method.

The following example displays a BigInteger value by using the default ToString() method. It also displays the string representations of the BigInteger value that results from using all the standard format specifiers supported by the BigInteger type. The examples are displayed using the formatting conventions of the "en-US" culture.

// Initialize a BigInteger value.
BigInteger value = BigInteger.Add(UInt64.MaxValue, 1024);

// Display value using the default ToString method.
outputBlock.Text += value.ToString() + "\n";
// Display value using some standard format specifiers.
outputBlock.Text += value.ToString("G") + "\n";
outputBlock.Text += value.ToString("D") + "\n";
outputBlock.Text += value.ToString("R") + "\n";
outputBlock.Text += value.ToString("X") + "\n";
// The example displays the following output on a system whose current 
// culture is en-US:
//       18446744073709552639
//       18446744073709552639
//       18446744073709552639
//       100000000000003FF      


Supported in: 5, 4

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions