Export (0) Print
Expand All

Int64.ToString Method (String, IFormatProvider)

Converts the numeric value of this instance to its equivalent string representation using the specified format and culture-specific format information.

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

'Declaration
<SecuritySafeCriticalAttribute> _
Public Function ToString ( _
	format As String, _
	provider As IFormatProvider _
) As String

Parameters

format
Type: System.String
A standard or custom numeric format string (see Remarks).
provider
Type: System.IFormatProvider
An IFormatProvider that supplies culture-specific formatting information about this instance.

Return Value

Type: System.String
The string representation of the value of this instance as specified by format and provider.

Implements

IFormattable.ToString(String, IFormatProvider)

If format is Nothing or an empty string (""), the return value for this instance is formatted with the general numeric format specifier ("G").

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

The provider parameter is an IFormatProvider that obtains a NumberFormatInfo object. The NumberFormatInfo provides culture-specific format information about this instance. If provider is Nothing, the return value for this instance is formatted with the NumberFormatInfo for the current culture.

The following code example formats an integral and a floating-point numeric value using the thread current culture, a specified culture, and all the standard numeric format specifiers. This code example uses two particular numeric types, but would yield similar results for any of the numeric base types (Byte, SByte, Int16, Int32, Int64, UInt16, UInt32, UInt64, Decimal, Single, and Double).


Option Strict On

Imports System.Globalization
Imports System.Threading

Module Example
   Public Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      ' Display string representations of numbers for en-us culture
      Dim ci As New CultureInfo("en-us")

      ' Output floating point values
      Dim floating As Double = 10761.937554
      outputBlock.Text += String.Format("C: {0}", _
              floating.ToString("C", ci))           ' Displays "C: $10,761.94" & vbCrLf
      outputBlock.Text += String.Format("E: {0}", _
              floating.ToString("E03", ci))         ' Displays "E: 1.076E+004" & vbCrLf
      outputBlock.Text += String.Format("F: {0}", _
              floating.ToString("F04", ci))         ' Displays "F: 10761.9376"          & vbCrLf
      outputBlock.Text += String.Format("G: {0}", _
              floating.ToString("G", ci))           ' Displays "G: 10761.937554" & vbCrLf
      outputBlock.Text += String.Format("N: {0}", _
              floating.ToString("N03", ci))         ' Displays "N: 10,761.938" & vbCrLf
      outputBlock.Text += String.Format("P: {0}", _
              (floating / 10000).ToString("P02", ci)) ' Displays "P: 107.62 %" & vbCrLf
      outputBlock.Text += String.Format("R: {0}", _
              floating.ToString("R", ci))           ' Displays "R: 10761.937554"             & vbCrLf
      outputBlock.Text += vbCrLf

      ' Output integral values
      Dim integral As Integer = 8395
      outputBlock.Text += String.Format("C: {0}", _
              integral.ToString("C", ci))           ' Displays "C: $8,395.00" & vbCrLf
      outputBlock.Text += String.Format("D: {0}", _
              integral.ToString("D6"))              ' Displays D: 008395""  & vbCrLf
      outputBlock.Text += String.Format("E: {0}", _
              integral.ToString("E03", ci))         ' Displays "E: 8.395E+003" & vbCrLf
      outputBlock.Text += String.Format("F: {0}", _
              integral.ToString("F01", ci))         ' Displays "F: 8395.0"     & vbCrLf
      outputBlock.Text += String.Format("G: {0}", _
              integral.ToString("G", ci))           ' Displays "G: 8395" & vbCrLf
      outputBlock.Text += String.Format("N: {0}", _
              integral.ToString("N01", ci))         ' Displays "N: 8,395.0" & vbCrLf
      outputBlock.Text += String.Format("P: {0}", _
              (integral / 10000).ToString("P02", ci)) ' Displays "P: 83.95 %" & vbCrLf
      outputBlock.Text += String.Format("X: 0x{0}", _
              integral.ToString("X", ci))           ' Displays "X: 0x20CB" & vbCrLf
      outputBlock.Text += vbCrLf
   End Sub
End Module


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

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

Community Additions

ADD
Show:
© 2015 Microsoft