Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Convert.ToString Method (Single)

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

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

public static string ToString (
	float value
)
public static String ToString (
	float value
)
public static function ToString (
	value : float
) : String
Not applicable.

Parameters

value

A single-precision floating point number.

Return Value

The String equivalent of the value of value.

This implementation is identical to Single.ToString.

The following code sample illustrates the conversion of a Single to a String, using ToString.

public void ConvertStringFloat(string stringVal) {
    float floatVal = 0;
    
    try {
        floatVal = System.Convert.ToSingle(stringVal);
        System.Console.WriteLine(
            "The string as a float is {0}.", floatVal);
    } 
    catch (System.OverflowException){
        System.Console.WriteLine(
            "The conversion from string-to-float overflowed.");
    }
    catch (System.FormatException) {
        System.Console.WriteLine(
            "The string is not formatted as a float.");
    }
    catch (System.ArgumentNullException) {
        System.Console.WriteLine(
            "The string is null.");
    }

    // Float to string conversion will not overflow.
    stringVal = System.Convert.ToString(floatVal);
    System.Console.WriteLine(
        "The float as a string is {0}.", stringVal);
}

public void ConvertStringFloat(String stringVal)
{
    float floatVal = 0;

    try {        
        floatVal = System.Convert.ToSingle(stringVal);
        System.Console.WriteLine("The string as a float is {0}.", 
            System.Convert.ToString(floatVal));
    }
    catch (System.OverflowException exp) {        
        System.Console.WriteLine(
            "The conversion from string-to-float overflowed.");
    }
    catch (System.FormatException exp) {                    
        System.Console.WriteLine("The string is not formatted as a float.");
    }
    catch (System.ArgumentNullException exp){        
        System.Console.WriteLine("The string is null.");
    }

    // Float to string conversion will not overflow.
    stringVal = System.Convert.ToString(floatVal);
    System.Console.WriteLine("The float as a string is {0}.", stringVal);
} //ConvertStringFloat

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

Show:
© 2014 Microsoft