Convert.ToDecimal Method (Int64)

May 11, 2014

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

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

public static decimal ToDecimal(
	long value
)

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 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";
   }
}


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft