Export (0) Print
Expand All

Convert.ToString Method

Converts the specified value to its equivalent String representation.

Overload List

Converts the value of the specified Boolean to its equivalent String representation.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function ToString(Boolean) As String
[C#] public static string ToString(bool);
[C++] public: static String* ToString(bool);
[JScript] public static function ToString(Boolean) : String;

Converts the value of the specified 8-bit unsigned integer to its equivalent String representation.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function ToString(Byte) As String
[C#] public static string ToString(byte);
[C++] public: static String* ToString(unsigned char);
[JScript] public static function ToString(Byte) : String;

Converts the value of the specified Unicode character to its equivalent String representation.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function ToString(Char) As String
[C#] public static string ToString(char);
[C++] public: static String* ToString(__wchar_t);
[JScript] public static function ToString(Char) : String;

Converts the value of the specified DateTime to its equivalent String representation.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function ToString(DateTime) As String
[C#] public static string ToString(DateTime);
[C++] public: static String* ToString(DateTime);
[JScript] public static function ToString(DateTime) : String;

Converts the value of the specified Decimal number to its equivalent String representation.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function ToString(Decimal) As String
[C#] public static string ToString(decimal);
[C++] public: static String* ToString(Decimal);
[JScript] public static function ToString(Decimal) : String;

Converts the value of the specified double-precision floating point number to its equivalent String representation.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function ToString(Double) As String
[C#] public static string ToString(double);
[C++] public: static String* ToString(double);
[JScript] public static function ToString(double) : String;

Converts the value of the specified 16-bit signed integer to its equivalent String representation.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function ToString(Short) As String
[C#] public static string ToString(short);
[C++] public: static String* ToString(short);
[JScript] public static function ToString(Int16) : String;

Converts the value of the specified 32-bit signed integer to its equivalent String representation.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function ToString(Integer) As String
[C#] public static string ToString(int);
[C++] public: static String* ToString(int);
[JScript] public static function ToString(int) : String;

Converts the value of the specified 64-bit signed integer to its equivalent String representation.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function ToString(Long) As String
[C#] public static string ToString(long);
[C++] public: static String* ToString(__int64);
[JScript] public static function ToString(long) : String;

Converts the value of the specified Object to its String representation.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function ToString(Object) As String
[C#] public static string ToString(object);
[C++] public: static String* ToString(Object*);
[JScript] public static function ToString(Object) : String;

Converts the value of the specified 8-bit signed integer to its equivalent String representation. This method is not CLS-compliant.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function ToString(SByte) As String
[C#] public static string ToString(sbyte);
[C++] public: static String* ToString(char);
[JScript] public static function ToString(SByte) : String;

Converts the value of the specified single-precision floating point number to its equivalent String representation.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function ToString(Single) As String
[C#] public static string ToString(float);
[C++] public: static String* ToString(float);
[JScript] public static function ToString(float) : String;

Returns the specified instance of String; no actual conversion is performed.

[Visual Basic] Overloads Public Shared Function ToString(String) As String
[C#] public static string ToString(string);
[C++] public: static String* ToString(String*);
[JScript] public static function ToString(String) : String;

Converts the value of the specified 16-bit unsigned integer to its equivalent String representation. This method is not CLS-compliant.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function ToString(UInt16) As String
[C#] public static string ToString(ushort);
[C++] public: static String* ToString(unsigned short);
[JScript] public static function ToString(UInt16) : String;

Converts the value of the specified 32-bit unsigned integer to its equivalent String representation. This method is not CLS-compliant.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function ToString(UInt32) As String
[C#] public static string ToString(uint);
[C++] public: static String* ToString(unsigned int);
[JScript] public static function ToString(UInt32) : String;

Converts the value of the specified 64-bit unsigned integer to its equivalent String representation. This method is not CLS-compliant.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function ToString(UInt64) As String
[C#] public static string ToString(ulong);
[C++] public: static String* ToString(unsigned __int64);
[JScript] public static function ToString(UInt64) : String;

Converts the value of the specified Boolean to its equivalent String representation.

[Visual Basic] Overloads Public Shared Function ToString(Boolean, IFormatProvider) As String
[C#] public static string ToString(bool, IFormatProvider);
[C++] public: static String* ToString(bool, IFormatProvider*);
[JScript] public static function ToString(Boolean, IFormatProvider) : String;

Converts the value of the specified 8-bit unsigned integer to its equivalent String representation.

[Visual Basic] Overloads Public Shared Function ToString(Byte, IFormatProvider) As String
[C#] public static string ToString(byte, IFormatProvider);
[C++] public: static String* ToString(unsigned char, IFormatProvider*);
[JScript] public static function ToString(Byte, IFormatProvider) : String;

Converts the value of an 8-bit unsigned integer to its equivalent String representation in a specified base.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function ToString(Byte, Integer) As String
[C#] public static string ToString(byte, int);
[C++] public: static String* ToString(unsigned char, int);
[JScript] public static function ToString(Byte, int) : String;

Converts the value of the specified Unicode character to its equivalent String representation.

[Visual Basic] Overloads Public Shared Function ToString(Char, IFormatProvider) As String
[C#] public static string ToString(char, IFormatProvider);
[C++] public: static String* ToString(__wchar_t, IFormatProvider*);
[JScript] public static function ToString(Char, IFormatProvider) : String;

Converts the value of the specified DateTime to its equivalent String representation.

[Visual Basic] Overloads Public Shared Function ToString(DateTime, IFormatProvider) As String
[C#] public static string ToString(DateTime, IFormatProvider);
[C++] public: static String* ToString(DateTime, IFormatProvider*);
[JScript] public static function ToString(DateTime, IFormatProvider) : String;

Converts the value of the specified Decimal number to its equivalent String representation.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function ToString(Decimal, IFormatProvider) As String
[C#] public static string ToString(decimal, IFormatProvider);
[C++] public: static String* ToString(Decimal, IFormatProvider*);
[JScript] public static function ToString(Decimal, IFormatProvider) : String;

Converts the value of the specified double-precision floating point number to its equivalent String representation.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function ToString(Double, IFormatProvider) As String
[C#] public static string ToString(double, IFormatProvider);
[C++] public: static String* ToString(double, IFormatProvider*);
[JScript] public static function ToString(double, IFormatProvider) : String;

Converts the value of the specified 16-bit signed integer to its equivalent String representation.

[Visual Basic] Overloads Public Shared Function ToString(Short, IFormatProvider) As String
[C#] public static string ToString(short, IFormatProvider);
[C++] public: static String* ToString(short, IFormatProvider*);
[JScript] public static function ToString(Int16, IFormatProvider) : String;

Converts the value of a 16-bit signed integer to its equivalent String representation in a specified base.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function ToString(Short, Integer) As String
[C#] public static string ToString(short, int);
[C++] public: static String* ToString(short, int);
[JScript] public static function ToString(Int16, int) : String;

Converts the value of the specified 32-bit signed integer to its equivalent String representation.

[Visual Basic] Overloads Public Shared Function ToString(Integer, IFormatProvider) As String
[C#] public static string ToString(int, IFormatProvider);
[C++] public: static String* ToString(int, IFormatProvider*);
[JScript] public static function ToString(int, IFormatProvider) : String;

Converts the value of a 32-bit signed integer to its equivalent String representation in a specified base.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function ToString(Integer, Integer) As String
[C#] public static string ToString(int, int);
[C++] public: static String* ToString(int, int);
[JScript] public static function ToString(int, int) : String;

Converts the value of the specified 64-bit signed integer to its equivalent String representation.

[Visual Basic] Overloads Public Shared Function ToString(Long, IFormatProvider) As String
[C#] public static string ToString(long, IFormatProvider);
[C++] public: static String* ToString(__int64, IFormatProvider*);
[JScript] public static function ToString(long, IFormatProvider) : String;

Converts the value of a 64-bit signed integer to its equivalent String representation in a specified base.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function ToString(Long, Integer) As String
[C#] public static string ToString(long, int);
[C++] public: static String* ToString(__int64, int);
[JScript] public static function ToString(long, int) : String;

Converts the value of the specified Object to its equivalent String representation using the specified culture-specific formatting information.

[Visual Basic] Overloads Public Shared Function ToString(Object, IFormatProvider) As String
[C#] public static string ToString(object, IFormatProvider);
[C++] public: static String* ToString(Object*, IFormatProvider*);
[JScript] public static function ToString(Object, IFormatProvider) : String;

Converts the value of the specified 8-bit signed integer to its equivalent String representation. This method is not CLS-compliant.

[Visual Basic] Overloads Public Shared Function ToString(SByte, IFormatProvider) As String
[C#] public static string ToString(sbyte, IFormatProvider);
[C++] public: static String* ToString(char, IFormatProvider*);
[JScript] public static function ToString(SByte, IFormatProvider) : String;

Converts the value of the specified single-precision floating point number to its equivalent String representation.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function ToString(Single, IFormatProvider) As String
[C#] public static string ToString(float, IFormatProvider);
[C++] public: static String* ToString(float, IFormatProvider*);
[JScript] public static function ToString(float, IFormatProvider) : String;

Returns the specified instance of String; no actual conversion is performed.

[Visual Basic] Overloads Public Shared Function ToString(String, IFormatProvider) As String
[C#] public static string ToString(string, IFormatProvider);
[C++] public: static String* ToString(String*, IFormatProvider*);
[JScript] public static function ToString(String, IFormatProvider) : String;

Converts the value of the specified 16-bit unsigned integer to its equivalent String representation. This method is not CLS-compliant.

[Visual Basic] Overloads Public Shared Function ToString(UInt16, IFormatProvider) As String
[C#] public static string ToString(ushort, IFormatProvider);
[C++] public: static String* ToString(unsigned short, IFormatProvider*);
[JScript] public static function ToString(UInt16, IFormatProvider) : String;

Converts the value of the specified 32-bit unsigned integer to its equivalent String representation. This method is not CLS-compliant.

[Visual Basic] Overloads Public Shared Function ToString(UInt32, IFormatProvider) As String
[C#] public static string ToString(uint, IFormatProvider);
[C++] public: static String* ToString(unsigned int, IFormatProvider*);
[JScript] public static function ToString(UInt32, IFormatProvider) : String;

Converts the value of the specified 64-bit unsigned integer to its equivalent String representation. This method is not CLS-compliant.

[Visual Basic] Overloads Public Shared Function ToString(UInt64, IFormatProvider) As String
[C#] public static string ToString(ulong, IFormatProvider);
[C++] public: static String* ToString(unsigned __int64, IFormatProvider*);
[JScript] public static function ToString(UInt64, IFormatProvider) : String;

Inherited from Object.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Overridable Function ToString() As String
[C#] public virtual string ToString();
[C++] public: virtual String* ToString();
[JScript] public function ToString() : String;

Example

[Visual Basic, C#, C++] The following code example converts a UInt64 (unsigned 64-bit integer) to a String with the ToString method, using an IFormatProvider object.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of ToString. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
' Example of the Convert.ToString( numeric types ) and 
' Convert.ToString( numeric types, IFormatProvider ) methods.
Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

Module ConvertNumericProviderDemo

    Sub Main( )

        ' Create a NumberFormatInfo object and set several of its
        ' properties that apply to numbers.
        Dim provider    As NumberFormatInfo = new NumberFormatInfo( )
        Dim formatter   As String           = "{0,22}   {1}"

        ' These properties will affect the conversion.
        provider.NegativeSign = "minus "
        provider.NumberDecimalSeparator = " point "

        ' These properties will not be applied.
        provider.NumberDecimalDigits = 2
        provider.NumberGroupSeparator = "."
        provider.NumberGroupSizes = New Integer( ) { 3 }

        ' Convert these values using default values and the
        ' format provider created above.
        Dim ByteA       As Byte     = 140
        Dim SByteA      As SByte    = Convert.ToSByte( -60 )
        Dim UInt16A     As UInt16   = Convert.ToUInt16( 61680 )
        Dim Int16A      As Short    = -3855

        Dim UInt32A     As UInt32   = Convert.ToUInt32( 4042322160 )
        Dim Int32A      As Integer  = -252645135   
        Dim UInt64A     As UInt64   = _
                            Convert.ToUInt64( 8138269444283625712 )
        Dim Int64A      As Long     = -1085102592571150095

        Dim SingleA     As Single   = -32.375F
        Dim DoubleA     As Double   = 61680.3855
        Dim DecimA      As Decimal  = 4042322160.252645135D
        Dim ObjDouble   As Object   = CType( -98765.4321, Object )

        Console.WriteLine( "This example of " & _
            "Convert.ToString( numeric types ) and " & vbCrLf & _
            "Convert.ToString( numeric types, IFormatProvider ) " & _
            vbCrLf & "converts values of each of the CLR base " & _
            "numeric types to strings, " & vbCrLf & "using " & _
            "default formatting and a NumberFormatInfo object." )
        Console.WriteLine( vbCrLf & _
            "Note: Of the several NumberFormatInfo properties " & _
            "that are changed, " & vbCrLf & "only the negative " & _
            "sign and decimal separator affect the conversions." )
        Console.WriteLine( vbCrLf & formatter, _
            "Default", "Format Provider" )
        Console.WriteLine( formatter, _
            "-------", "---------------" )

        ' Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), _
            Convert.ToString( ByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( SByteA ), _
            Convert.ToString( SByteA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), _
            Convert.ToString( UInt16A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int16A ), _
            Convert.ToString( Int16A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), _
            Convert.ToString( UInt32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int32A ), _
            Convert.ToString( Int32A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), _
            Convert.ToString( UInt64A, provider ) )
        Console.WriteLine( formatter, Convert.ToString( Int64A ), _
            Convert.ToString( Int64A, provider ) )

        Console.WriteLine( formatter, Convert.ToString( SingleA ), _
            Convert.ToString( SingleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), _
            Convert.ToString( DoubleA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( DecimA ), _
            Convert.ToString( DecimA, provider ) )
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), _
            Convert.ToString( ObjDouble, provider ) )
    End Sub
End Module

' This example of Convert.ToString( numeric types ) and
' Convert.ToString( numeric types, IFormatProvider )
' converts values of each of the CLR base numeric types to strings,
' using default formatting and a NumberFormatInfo object.
' 
' Note: Of the several NumberFormatInfo properties that are changed,
' only the negative sign and decimal separator affect the conversions.
' 
'                Default   Format Provider
'                -------   ---------------
'                    140   140
'                    -60   minus 60
'                  61680   61680
'                  -3855   minus 3855
'             4042322160   4042322160
'             -252645135   minus 252645135
'    8138269444283625712   8138269444283625712
'   -1085102592571150095   minus 1085102592571150095
'                -32.375   minus 32 point 375
'             61680.3855   61680 point 3855
'   4042322160.252645135   4042322160 point 252645135
'            -98765.4321   minus 98765 point 4321

[C#] 
// Example of the Convert.ToString( numeric types ) and 
// Convert.ToString( numeric types, IFormatProvider ) methods.
using System;
using System.Globalization;

class ConvertNumericProviderDemo
{
    static void Main( )
    {
        // Create a NumberFormatInfo object and set several of its
        // properties that apply to numbers.
        NumberFormatInfo provider = new NumberFormatInfo( );
        string formatter = "{0,22}   {1}";

        // These properties will affect the conversion.
        provider.NegativeSign = "minus ";
        provider.NumberDecimalSeparator = " point ";

        // These properties will not be applied.
        provider.NumberDecimalDigits = 2;
        provider.NumberGroupSeparator = ".";
        provider.NumberGroupSizes = new int[ ] { 3 };

        // Convert these values using default values and the
        // format provider created above.
        byte    ByteA       = 140;
        SByte   SByteA      = -60;
        UInt16  UInt16A     = 61680;
        short   Int16A      = -3855;

        UInt32  UInt32A     = 4042322160;
        int     Int32A      = -252645135;
        UInt64  UInt64A     = 8138269444283625712;
        long    Int64A      = -1085102592571150095;

        float   SingleA     = -32.375F;
        double  DoubleA     = 61680.3855;
        decimal DecimA      = 4042322160.252645135M;
        object  ObjDouble   = (object)( -98765.4321 );

        Console.WriteLine( "This example of " +
            "Convert.ToString( numeric types ) and \n" +
            "Convert.ToString( numeric types, IFormatProvider ) \n" +
            "converts values of each of the CLR base numeric types " +
            "to strings, \nusing default formatting and a " +
            "NumberFormatInfo object." );
        Console.WriteLine(
            "\nNote: Of the several NumberFormatInfo " +
            "properties that are changed, \nonly the negative sign " +
            "and decimal separator affect the conversions.\n" );
        Console.WriteLine( formatter, "Default", "Format Provider" );
        Console.WriteLine( formatter, "-------", "---------------" );

        // Convert the values with and without a format provider.
        Console.WriteLine( formatter, Convert.ToString( ByteA ), 
            Convert.ToString( ByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( SByteA ), 
            Convert.ToString( SByteA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt16A ), 
            Convert.ToString( UInt16A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int16A ), 
            Convert.ToString( Int16A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( UInt32A ), 
            Convert.ToString( UInt32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int32A ), 
            Convert.ToString( Int32A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( UInt64A ), 
            Convert.ToString( UInt64A, provider ) );
        Console.WriteLine( formatter, Convert.ToString( Int64A ), 
            Convert.ToString( Int64A, provider ) );

        Console.WriteLine( formatter, Convert.ToString( SingleA ), 
            Convert.ToString( SingleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DoubleA ), 
            Convert.ToString( DoubleA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( DecimA ), 
            Convert.ToString( DecimA, provider ) );
        Console.WriteLine( formatter, Convert.ToString( ObjDouble ), 
            Convert.ToString( ObjDouble, provider ) );
    }
}

/*
This example of Convert.ToString( numeric types ) and
Convert.ToString( numeric types, IFormatProvider )
converts values of each of the CLR base numeric types to strings,
using default formatting and a NumberFormatInfo object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/ 

[C++] 
// Example of the Convert::ToString( numeric types ) and 
// Convert::ToString( numeric types, IFormatProvider* ) methods.
#using <mscorlib.dll>
using namespace System;
using namespace System::Globalization;

void main( )
{
    // Create a NumberFormatInfo object and set several of its
    // properties that apply to numbers.
    NumberFormatInfo*   provider = new NumberFormatInfo( );
    String*             formatter = S"{0,22}   {1}";

    // These properties will affect the conversion.
    provider->NegativeSign = S"minus ";
    provider->NumberDecimalSeparator = S" point ";

    // These properties will not be applied.
    provider->NumberDecimalDigits = 2;
    provider->NumberGroupSeparator = S".";
    Int32 sizes __gc [] = { 3 };
    provider->NumberGroupSizes = sizes;

    // Convert these values using default values and the
    // format provider created above.
    Byte        ByteA       = 140;
    SByte       SByteA      = -60;
    UInt16      UInt16A     = 61680;
    short       Int16A      = -3855;

    UInt32      UInt32A     = 4042322160;
    int         Int32A      = -252645135;
    UInt64      UInt64A     = 8138269444283625712;
    __int64     Int64A      = -1085102592571150095;

    float       SingleA     = -32.375F;
    double      DoubleA     = 61680.3855;
    Decimal     DecimA      = 
                    Convert::ToDecimal( S"4042322160.252645135" );
    Object*     ObjDouble   = __box( -98765.4321 );

    Console::WriteLine( S"This example of " 
        S"Convert::ToString( numeric types ) and \n" 
        S"Convert::ToString( numeric types, IFormatProvider* ) \n" 
        S"converts values of each of the CLR base numeric types " 
        S"to strings, \nusing default formatting and a " 
        S"NumberFormatInfo object." );
    Console::WriteLine(
        S"\nNote: Of the several NumberFormatInfo " 
        S"properties that are changed, \nonly the negative sign " 
        S"and decimal separator affect the conversions.\n" );
    Console::WriteLine( formatter, S"Default", S"Format Provider" );
    Console::WriteLine( formatter, S"-------", S"---------------" );

    // Convert the values with and without a format provider.
    Console::WriteLine( formatter, Convert::ToString( ByteA ), 
        Convert::ToString( ByteA, provider ) );
    Console::WriteLine( formatter, Convert::ToString( SByteA ), 
        Convert::ToString( SByteA, provider ) );
    Console::WriteLine( formatter, Convert::ToString( UInt16A ), 
        Convert::ToString( UInt16A, provider ) );
    Console::WriteLine( formatter, Convert::ToString( Int16A ), 
        Convert::ToString( Int16A, provider ) );

    Console::WriteLine( formatter, Convert::ToString( UInt32A ), 
        Convert::ToString( UInt32A, provider ) );
    Console::WriteLine( formatter, Convert::ToString( Int32A ), 
        Convert::ToString( Int32A, provider ) );
    Console::WriteLine( formatter, Convert::ToString( UInt64A ), 
        Convert::ToString( UInt64A, provider ) );
    Console::WriteLine( formatter, Convert::ToString( Int64A ), 
        Convert::ToString( Int64A, provider ) );

    Console::WriteLine( formatter, Convert::ToString( SingleA ), 
        Convert::ToString( SingleA, provider ) );
    Console::WriteLine( formatter, Convert::ToString( DoubleA ), 
        Convert::ToString( DoubleA, provider ) );
    Console::WriteLine( formatter, Convert::ToString( DecimA ), 
        Convert::ToString( DecimA, provider ) );
    Console::WriteLine( formatter, Convert::ToString( ObjDouble ), 
        Convert::ToString( ObjDouble, provider ) );
}

/*
This example of Convert::ToString( numeric types ) and
Convert::ToString( numeric types, IFormatProvider* )
converts values of each of the CLR base numeric types to strings,
using default formatting and a NumberFormatInfo object.

Note: Of the several NumberFormatInfo properties that are changed,
only the negative sign and decimal separator affect the conversions.

               Default   Format Provider
               -------   ---------------
                   140   140
                   -60   minus 60
                 61680   61680
                 -3855   minus 3855
            4042322160   4042322160
            -252645135   minus 252645135
   8138269444283625712   8138269444283625712
  -1085102592571150095   minus 1085102592571150095
               -32.375   minus 32 point 375
            61680.3855   61680 point 3855
  4042322160.252645135   4042322160 point 252645135
           -98765.4321   minus 98765 point 4321
*/ 

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

Convert Class | Convert Members | System Namespace

Show:
© 2014 Microsoft