Double::ToString Method
Converts the numeric value of this instance to its equivalent string representation.
Assembly: mscorlib (in mscorlib.dll)
The return value can be PositiveInfinitySymbol, NegativeInfinitySymbol, NaNSymbol, or a string of the form:
[sign]integral-digits[.[fractional-digits]][e[sign]exponential-digits]
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 elements listed in the following table are supported.
Element | Description |
|---|---|
sign | A negative sign or positive sign symbol. |
integral-digits | 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. |
fractional-digits | A series of digits specifying the fractional part of the number. |
'e' | A lowercase character 'e', indicating exponential (scientific) notation. |
exponential-digits | 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".
This version of the ToString method implicitly uses the general numeric format specifier ("G") and the NumberFormatInfo for the current culture.
The .NET Framework provides extensive formatting support, which is described in greater detail in the following formatting topics:
For more information about numeric format specifiers, see Standard Numeric Format Strings and Custom Numeric Format Strings.
For more information about formatting, see Formatting Types.
The following example uses the default Double::ToString() method to display the string representations of a number of Double values.
The following example illustrates the use of ToString.
bool done = false; String^ inp; do { Console::Write( "Enter a real number: " ); inp = Console::ReadLine(); try { d = Double::Parse( inp ); Console::WriteLine( "You entered {0}.", d ); 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 );
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.