Convert.ToDecimal Method (Int64)


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


Type: System.Int64

The 64-bit signed integer to convert.

Return Value

Type: System.Decimal

A decimal number that is equivalent to value.

The following example converts an Int64 value to a Decimal value.

public void ConvertLongDecimal(long longVal) {

	decimal	decimalVal;

	// Long to decimal conversion cannot overflow.
	decimalVal = System.Convert.ToDecimal(longVal);
	System.Console.WriteLine("{0} as a decimal is {1}", 
			longVal, decimalVal);

	// Decimal to long conversion can overflow.
	try {
		longVal = System.Convert.ToInt64(decimalVal);
		System.Console.WriteLine("{0} as a long is {1}", 
			decimalVal, longVal);
	catch (System.OverflowException) {
			"Overflow in decimal-to-long conversion.");

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