Export (0) Print
Expand All

Decimal Explicit Conversion (Decimal to Double)

Defines an explicit conversion of a Decimal to a double-precision floating-point number.

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

public static explicit operator double (
	decimal value
)

Parameters

value
Type: System.Decimal

The value to convert.

Return Value

Type: System.Double
A double-precision floating-point number that represents the converted Decimal.

This operation can result in a loss of precision, because a double-precision floating-point number has fewer significant digits than a Decimal.

This operator supports the explicit conversion of a Decimal to a Double. The syntax for such explicit conversions is language-dependent, and individual language compilers can provide different implementations and return different results. The example illustrates the different return values when you explicitly convert a Decimal value to a Double value by using C#, C++, and Visual Basic. To perform a conversion that is independent of language, you can call the ToDouble or the Convert.ToDouble(Decimal) method.

The following example converts Decimal numbers to Double values by using the explicit Decimal to Double conversion.

using System;

class Example
{
    public static void Main( )
    {
        // Define an array of decimal values. 
        decimal[] values = { 0.0000000000000000000000000001M, 
                             0.0000000000123456789123456789M,
                             123M, new decimal(123000000, 0, 0, false, 6),
                             123456789.123456789M, 
                             123456789123456789123456789M, 
                             decimal.MinValue, decimal.MaxValue };
        // Convert each value to a double. 
        foreach (var value in values) {
            double dblValue = (double) value;
            Console.WriteLine("{0} ({1}) --> {2} ({3})", value,
                              value.GetType().Name, dblValue, 
                              dblValue.GetType().Name);
       } 
    }
}
// The example displays the following output: 
//    0.0000000000000000000000000001 (Decimal) --> 1E-28 (Double) 
//    0.0000000000123456789123456789 (Decimal) --> 1.23456789123457E-11 (Double) 
//    123 (Decimal) --> 123 (Double) 
//    123.000000 (Decimal) --> 123 (Double) 
//    123456789.123456789 (Decimal) --> 123456789.123457 (Double) 
//    123456789123456789123456789 (Decimal) --> 1.23456789123457E+26 (Double) 
//    -79228162514264337593543950335 (Decimal) --> -7.92281625142643E+28 (Double) 
//    79228162514264337593543950335 (Decimal) --> 7.92281625142643E+28 (Double)

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8
Show:
© 2015 Microsoft