ToDecimal Method (Int64)

Convert.ToDecimal Method (Int64)

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Converts the value of the specified 64-bit signed integer to an equivalent Decimal number.

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

'Declaration
Public Shared Function ToDecimal ( _
	value As Long _
) As Decimal

Parameters

value
Type: System.Int64
A 64-bit signed integer.

Return Value

Type: System.Decimal
A Decimal number equivalent to the value of value.

The following code sample illustrates the conversion of an Int64 value to a Decimal one, using ToDecimal.


Public Sub ConvertLongDecimal(ByVal longVal As Long)

   Dim decimalVal As Decimal

   'Long to Decimal conversion cannot overflow.
   decimalVal = System.Convert.ToDecimal(longVal)
   outputBlock.Text &= String.Format("{0} as a Decimal is {1}", _
                             longVal, decimalVal) & vbCrLf

   'Decimal to Long conversion can overflow.
   Try
      longVal = System.Convert.ToInt64(decimalVal)
      outputBlock.Text &= String.Format("{0} as a Long is {1}", _
                                decimalVal, longVal) & vbCrLf
   Catch exception As System.OverflowException
      outputBlock.Text &= String.Format( _
          "Overflow in decimal-to-long conversion.") & vbCrLf
   End Try
End Sub


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft