This topic has not yet been rated - Rate this topic

# Decimal.ToDouble Method

February 14, 2014

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

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)
```'Declaration
Public Shared Function ToDouble ( _
d As Decimal _
) As Double
```

#### Parameters

d
Type: System.Decimal
The Decimal value 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.

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

```
' Example of the Decimal.ToSingle and Decimal.ToDouble methods.

Module Example

Dim formatter As String = "{0,30}{1,17}{2,23}"

' Convert the Decimal argument; no exceptions are thrown.
Sub DecimalToSgl_Dbl(ByVal outputBlock As System.Windows.Controls.TextBlock, ByVal argument As Decimal)

Dim SingleValue As Object
Dim DoubleValue As Object

' Convert the argument to a Single value.
SingleValue = Decimal.ToSingle(argument)

' Convert the argument to a Double value.
DoubleValue = Decimal.ToDouble(argument)

outputBlock.Text &= String.Format(formatter, argument, _
SingleValue, DoubleValue) & vbCrLf
End Sub

Public Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)

outputBlock.Text &= String.Format("This example of the " & vbCrLf & _
"  Decimal.ToSingle( Decimal ) and " & vbCrLf & _
"  Decimal.ToDouble( Decimal ) " & vbCrLf & "methods " & _
"generates the following output. It " & vbCrLf & _
"displays several converted Decimal values." & vbCrLf) & vbCrLf
outputBlock.Text &= String.Format(formatter, "Decimal argument", _
"Single", "Double") & vbCrLf
outputBlock.Text &= String.Format(formatter, "----------------", _
"------", "------") & vbCrLf

' Convert Decimal values and display the results.
DecimalToSgl_Dbl(outputBlock, 0.0000000000000000000000000001D)
DecimalToSgl_Dbl(outputBlock, 0.0000000000112233445566778899D)
DecimalToSgl_Dbl(outputBlock, 123D)
DecimalToSgl_Dbl(outputBlock, New Decimal(123000000, 0, 0, False, 6))
DecimalToSgl_Dbl(outputBlock, 123456789.123456789D)
DecimalToSgl_Dbl(outputBlock, 123456789123456789123456789D)
DecimalToSgl_Dbl(outputBlock, Decimal.MinValue)
DecimalToSgl_Dbl(outputBlock, Decimal.MaxValue)
End Sub
End Module

' This example of the
'   Decimal.ToSingle( Decimal ) and
'   Decimal.ToDouble( Decimal )
' methods generates the following output. It
' displays several converted Decimal values.
'
'               Decimal argument           Single                 Double
'               ----------------           ------                 ------
' 0.0000000000000000000000000001            1E-28                  1E-28
' 0.0000000000112233445566778899     1.122334E-11   1.12233445566779E-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

```

#### Windows Phone OS

Supported in: 8.0, 7.1, 7.0

Windows Phone

#### Reference

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show: