This documentation is archived and is not being maintained.

BigInteger::ToString Method (String)

Converts the numeric value of the current BigInteger object to its equivalent string representation by using the specified format.

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

public:
String^ ToString(
	String^ format
)

Parameters

format
Type: System::String
A standard or custom numeric format string.

Return Value

Type: System::String
The string representation of the current BigInteger value in the format specified by the format parameter.

ExceptionCondition
FormatException

format is not a valid format string.

The format parameter can be any valid standard numeric format specifier, or any combination of custom numeric format specifiers. If format is equal to String::Empty or is nullptr, the return value of the current BigInteger object is formatted with the general format specifier ("G"). If format is any other value, the method throws a FormatException.

In most cases, 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. However, BigInteger supports the "R" standard format specifier, which is intended to round-trip numeric values. The string returned by the ToString(String) method with the "R" format string preserves the whole BigInteger value and can then be parsed with the Parse or TryParse method to restore its original value without any loss of data. The following example illustrates that a string output using the "R" format string can then be parsed by the Parse method without any data loss.

No code example is currently available or this language may not be supported.

The .NET Framework provides extensive formatting support, which is described in greater detail in the following formatting topics:

The format of the returned string is determined by the NumberFormatInfo object for the current culture. Depending on the format parameter, this object controls symbols such as the negative sign, the group separator, and the decimal point symbol in the output string. To provide formatting information for cultures other than the current culture, call the ToString(String, IFormatProvider) overload.

The following example initializes a BigInteger value and displays it by using each standard format string and some custom format strings.

No code example is currently available or this language may not be supported.

.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.
Show: