ToString Method

Single::ToString Method ()


Converts the numeric value of this instance to its equivalent string representation.

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

virtual String^ ToString() override

Return Value

Type: System::String^

The string representation of the value of this instance.

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

To use format

For culture

Use the overload

Default ("G") format

A specific culture


A specific format

Default (current) culture


A specific format

A specific culture

ToString(String^, IFormatProvider^)

The return value can be PositiveInfinitySymbol, NegativeInfinitySymbol, NaNSymbol, or a string of the form:


Optional elements are framed in square brackets ([ and ]). Elements that contain the term "digits" consist of a series of numeric characters ranging from 0 to 9. The following table lists each element:




A negative sign or positive sign symbol.


A series of digits specifying the integral part of the number. Integral-digits can be absent if there are fractional-digits.


A culture-specific decimal point symbol.


A series of digits specifying the fractional part of the number.


A lowercase character 'e', indicating exponential (scientific) notation.


A series of digits specifying an exponent.

Some examples of the return value are "100", "-123,456,789", "123.45e+6", "500", "3.1416", "600", "-0.123", and "-Infinity".

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

The following example uses the default Single::ToString method to display the string representations of a number of Single values.

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

The following code example illustrates the use of the Parse(String^) method along with the ToString() method.

bool done = false;
String^ inp;
   Console::Write( "Enter a real number: " );
   inp = Console::ReadLine();
      s = Single::Parse( inp );
      Console::WriteLine( "You entered {0}.", s );
      done = true;
   catch ( FormatException^ ) 
      Console::WriteLine( "You did not enter a number." );
   catch ( Exception^ e ) 
      Console::WriteLine( "An exception occurred while parsing your response: {0}", e );
while (  !done );

Universal Windows Platform
Available since 4.5
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
© 2015 Microsoft