This topic has not yet been rated - Rate this topic

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 some standard format specifiers. 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.
Console.WriteLine(value.ToString());     
// Display value using some standard format specifiers.
Console.WriteLine(value.ToString("G"));
Console.WriteLine(value.ToString("C"));
Console.WriteLine(value.ToString("D"));
Console.WriteLine(value.ToString("F"));
Console.WriteLine(value.ToString("N"));
Console.WriteLine(value.ToString("X"));       
// The example displays the following output on a system whose current 
// culture is en-US:
//       18446744073709552639
//       18446744073709552639
//       $18,446,744,073,709,552,639.00
//       18446744073709552639
//       18446744073709552639.00
//       18,446,744,073,709,552,639.00
//       100000000000003FF      


.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.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.