Decimal::ToDouble Method (Decimal)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

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

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

static double ToDouble(
	Decimal d


Type: System::Decimal

The decimal number to convert.

Return Value

Type: System::Double

A double-precision floating-point number equivalent to d.

This operation can produce round-off errors because a double-precision floating-point number has fewer significant digits than a Decimal.

You can also convert a Decimal to a Double value by using the Explicit(Decimal to Double) assignment operator. Because the conversion can entail a loss of precision, you must use a casting operator in C# or a conversion function in Visual Basic.

The following code example converts Decimal numbers to Double values using ToDouble method.

// Example of the Decimal::ToSingle and Decimal::ToDouble methods.
using namespace System;
#define formatter "{0,30}{1,17}{2,23}"

// Convert the Decimal argument; no exceptions are thrown.
void DecimalToSgl_Dbl( Decimal argument )
   Object^ SingleValue;
   Object^ DoubleValue;

   // Convert the argument to a float value.
   SingleValue = Decimal::ToSingle( argument );

   // Convert the argument to a double value.
   DoubleValue = Decimal::ToDouble( argument );
   Console::WriteLine( formatter, argument, SingleValue, DoubleValue );

int main()
   Console::WriteLine( "This example of the \n"
   "  Decimal::ToSingle( Decimal ) and \n"
   "  Decimal::ToDouble( Decimal ) \nmethods "
   "generates the following output. It \ndisplays "
   "several converted Decimal values.\n" );
   Console::WriteLine( formatter, "Decimal argument", "float", "double" );
   Console::WriteLine( formatter, "----------------", "-----", "------" );

   // Convert Decimal values and display the results.
   DecimalToSgl_Dbl( Decimal::Parse(  "0.0000000000000000000000000001" ) );
   DecimalToSgl_Dbl( Decimal::Parse(  "0.0000000000123456789123456789" ) );
   DecimalToSgl_Dbl( Decimal::Parse(  "123" ) );
   DecimalToSgl_Dbl( Decimal(123000000,0,0,false,6) );
   DecimalToSgl_Dbl( Decimal::Parse(  "123456789.123456789" ) );
   DecimalToSgl_Dbl( Decimal::Parse(  "123456789123456789123456789" ) );
   DecimalToSgl_Dbl( Decimal::MinValue );
   DecimalToSgl_Dbl( Decimal::MaxValue );

This example of the
  Decimal::ToSingle( Decimal ) and
  Decimal::ToDouble( Decimal )
methods generates the following output. It
displays several converted Decimal values.

              Decimal argument            float                 double
              ----------------            -----                 ------
0.0000000000000000000000000001            1E-28                  1E-28
0.0000000000123456789123456789     1.234568E-11   1.23456789123457E-11
                           123              123                    123
                    123.000000              123                    123
           123456789.123456789     1.234568E+08       123456789.123457
   123456789123456789123456789     1.234568E+26   1.23456789123457E+26
-79228162514264337593543950335    -7.922816E+28  -7.92281625142643E+28
 79228162514264337593543950335     7.922816E+28   7.92281625142643E+28

Universal Windows Platform
Available since 8
.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