Freigeben über


Convert.ToDecimal Method (Int64)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

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

Syntax

'Declaration
Public Shared Function ToDecimal ( _
    value As Long _
) As Decimal
public static decimal ToDecimal(
    long value
)

Parameters

Return Value

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

Examples

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
public void ConvertLongDecimal(long longVal)
{
   decimal decimalVal;

   // Long to decimal conversion cannot overflow.
   decimalVal = System.Convert.ToDecimal(longVal);
   outputBlock.Text += String.Format("{0} as a decimal is {1}",
         longVal, decimalVal) + "\n";

   // Decimal to long conversion can overflow.
   try
   {
      longVal = System.Convert.ToInt64(decimalVal);
      outputBlock.Text += String.Format("{0} as a long is {1}",
         decimalVal, longVal) + "\n";
   }
   catch (System.OverflowException)
   {
      outputBlock.Text += String.Format(
         "Overflow in decimal-to-long conversion.") + "\n";
   }
}

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.