Aracılığıyla paylaş


BigInteger.ToString Method (String)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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)

Syntax

'Declaration
Public Function ToString ( _
    format As String _
) As String
public string ToString(
    string format
)

Parameters

  • format
    Type: System.String
    A standard numeric format string. The BigInteger type supports the "D", "G", "R", and "X" standard format strings.

Return Value

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

Exceptions

Exception Condition
FormatException

format is not a valid format string.

Remarks

The format parameter can be one of four valid standard numeric format specifiers ("D", "G", "R", and "X"). If format is equal to String.Empty or is nulla null reference (Nothing in Visual Basic), 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.

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.

Examples

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

Dim value As BigInteger = BigInteger.MinusOne * BigInteger.Multiply(UInt64.MaxValue, 48) +
                          17702077233584712662ul
Dim specifiers() As String = { "D", "D25", "G", "R", "X" }

For Each specifier As String In specifiers
   outputBlock.Text += String.Format("{0}: {1}", specifier, value.ToString(specifier)) & vbCrLf
Next
' The example displays the following output:
'       D: -903145792771643190182
'       D25: -0000903145792771643190182
'       G: -903145792771643190182
'       R: -903145792771643190182
'       X: CF0A55968BB1A7545A
BigInteger value = BigInteger.MinusOne * UInt64.MaxValue * 48 + 17702077233584712662;
string[] specifiers = { "D", "D25", "G", "R", "X" };

foreach (string specifier in specifiers)
   outputBlock.Text += String.Format("{0}: {1}\n", specifier, value.ToString(specifier));

// The example displays the following output:
//       D: -903145792771643190182
//       D25: -0000903145792771643190182
//       G: -903145792771643190182
//       R: -903145792771643190182
//       X: CF0A55968BB1A7545A

Version Information

Silverlight

Supported in: 5, 4

Platforms

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