Convert.ToDouble Method (Single)

Converts the value of the specified single-precision floating point number to an equivalent double-precision floating point number.

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

public static double ToDouble (
	float value
)
public static double ToDouble (
	float value
)
public static function ToDouble (
	value : float
) : double

Parameters

value

A single-precision floating point number.

Return Value

A double-precision floating point number equivalent to the value of value.

The following code sample illustrates the conversion of a Single value to a Double one, using ToDouble.

public void CovertDoubleFloat(double doubleVal) {    
    float floatVal = 0;

    // Double to float conversion can overflow.
    try {
        floatVal = System.Convert.ToSingle(doubleVal);
        System.Console.WriteLine("{0} as a float is {1}",
            doubleVal, floatVal);
    } 
    catch (System.OverflowException) {
        System.Console.WriteLine(
            "Overflow in double-to-float conversion.");
    }

    // Conversion from float to double cannot overflow.
    doubleVal = System.Convert.ToDouble(floatVal);
    System.Console.WriteLine("{0} as a double is: {1}",
        floatVal, doubleVal);
}

public void CovertDoubleFloat(double doubleVal)
{
    float floatVal = 0;

    // Double to float conversion can overflow.
    try {        
        floatVal = System.Convert.ToSingle(doubleVal);
        System.Console.WriteLine("{0} as a float is {1}", 
            System.Convert.ToString(doubleVal), 
            System.Convert.ToString(floatVal));
    }
    catch (System.OverflowException exp) {        
        System.Console.WriteLine("Overflow in double-to-float conversion.");
    }

    // Conversion from float to double cannot overflow.
    doubleVal = System.Convert.ToDouble(floatVal);
    System.Console.WriteLine("{0} as a double is: {1}", 
        System.Convert.ToString(floatVal), 
        System.Convert.ToString(doubleVal));
} //CovertDoubleFloat

Windows 98, Windows 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 .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show: