Export (0) Print
Expand All

BigInteger.ToString Method (IFormatProvider)

Converts the numeric value of the current BigInteger object to its equivalent string representation by using the specified culture-specific formatting information.

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

'Declaration
Public Function ToString ( _
	provider As IFormatProvider _
) As String

Parameters

provider
Type: System.IFormatProvider

An object that supplies culture-specific formatting information.

Return Value

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

The ToString(IFormatProvider) method formats a BigInteger value in the default ("G", or general) format by using the NumberFormatInfo object of a specified culture. If you want to specify a different format or the current culture, use the other overloads of the ToString method, as follows:

To use format

For culture

Use the overload

Default ("G") format

Default (current) culture

ToString

A specific format

Default (current) culture

ToString(String)

A specific format

A specific culture

ToString(String, IFormatProvider)

The ToString(IFormatProvider) 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.

The provider parameter is an IFormatProvider implementation. Its GetFormat method returns a NumberFormatInfo object that provides culture-specific information about the format of the string returned by this method. If provider is Nothing, the BigInteger value is formatted using the NumberFormatInfo object of the current culture. The only property of the NumberFormatInfo object that controls the string representation of the BigInteger value using the general format specifier is NumberFormatInfo.NegativeSign, which defines the character that represents the negative sign.

The provider parameter can be one of the following:

The following example instantiates a custom NumberFormatInfo object that defines the tilde (~) as a negative sign. The ToString(IFormatProvider) method then uses the custom NumberFormatInfo object to display a negative BigInteger value.

Dim number As BigInteger = 9867857831128
number = BigInteger.Pow(number, 3) * BigInteger.MinusOne

Dim bigIntegerProvider As New NumberFormatInfo()
bigIntegerProvider.NegativeSign = "~"      

Console.WriteLine(number.ToString(bigIntegerProvider))

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4

.NET Framework Client Profile

Supported in: 4

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1

Windows Phone 8.1, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft