Decimal Constructor (Int64)

July 28, 2014

Initializes a new instance of Decimal to the value of the specified 64-bit signed integer.

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

public Decimal(
	long value
)

Parameters

value
Type: System.Int64
The value to represent as a Decimal.

The following code example creates several Decimal numbers using the constructor overload that initializes a Decimal structure with an Int64 value.


// Example of the decimal( long ) constructor.
using System;

class Example
{
   // Create a decimal object and display its value.
   public static void CreateDecimal(System.Windows.Controls.TextBlock outputBlock, long value, string valToStr)
   {
      decimal decimalNum = new decimal(value);

      // Format the constructor for display.
      string ctor = String.Format("decimal( {0} )", valToStr);

      // Display the constructor and its value.
      outputBlock.Text += String.Format("{0,-35}{1,22}", ctor, decimalNum) + "\n";
   }

   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      outputBlock.Text += "This example of the decimal( long ) " +
          "constructor \ngenerates the following output.\n" + "\n";
      outputBlock.Text += String.Format("{0,-35}{1,22}", "Constructor", "Value") + "\n";
      outputBlock.Text += String.Format("{0,-35}{1,22}", "-----------", "-----") + "\n";

      // Construct decimal objects from long values.
      CreateDecimal(outputBlock, long.MinValue, "long.MinValue");
      CreateDecimal(outputBlock, long.MaxValue, "long.MaxValue");
      CreateDecimal(outputBlock, 0L, "0L");
      CreateDecimal(outputBlock, 999999999999999999, "999999999999999999");
      CreateDecimal(outputBlock, 0x2000000000000000, "0x2000000000000000");
      CreateDecimal(outputBlock, unchecked((long)0xE000000000000000),
          "(long)0xE000000000000000");
   }
}

/*
This example of the decimal( long ) constructor
generates the following output.

Constructor                                         Value
-----------                                         -----
decimal( long.MinValue )             -9223372036854775808
decimal( long.MaxValue )              9223372036854775807
decimal( 0 )                                            0
decimal( 999999999999999999 )          999999999999999999
decimal( 0x2000000000000000 )         2305843009213693952
decimal( (long)0xE000000000000000 )  -2305843009213693952
*/


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft