Export (0) Print
Expand All

Decimal Constructor (Int64)

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
)
public Decimal (
	long value
)
public function Decimal (
	value : long
)

Parameters

value

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 DecimalCtorLDemo
{
    // Create a decimal object and display its value.
    public static void CreateDecimal( 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.
        Console.WriteLine( "{0,-35}{1,22}", ctor, decimalNum );
    }
    
    public static void Main( )
    {
        Console.WriteLine( "This example of the decimal( long ) " +
            "constructor \ngenerates the following output.\n" );
        Console.WriteLine( "{0,-35}{1,22}", "Constructor", "Value" );
        Console.WriteLine( "{0,-35}{1,22}", "-----------", "-----" );

        // Construct decimal objects from long values.
        CreateDecimal( long.MinValue, "long.MinValue" );
        CreateDecimal( long.MaxValue, "long.MaxValue" );
        CreateDecimal( 0L, "0L" );
        CreateDecimal( 999999999999999999, "999999999999999999" );
        CreateDecimal( 0x2000000000000000, "0x2000000000000000" );
        CreateDecimal( 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
*/

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

class DecimalCtorLDemo
{   
    // Create a decimal object and display its value.
    public static void CreateDecimal(long value, String valToStr)
    {
        System.Decimal decimalNum =  new System.Decimal(value);
        
        // Format the constructor for display.
        String ctor = String.Format("decimal( {0} )", valToStr);
        
        // Display the constructor and its value.
        Console.WriteLine("{0,-35}{1,22}", ctor, decimalNum);
    } //CreateDecimal
        
    public static void main(String[] args)
    {
        Console.WriteLine(("This example of the decimal( long ) " 
            + "constructor \ngenerates the following output.\n"));
        Console.WriteLine("{0,-35}{1,22}", "Constructor", "Value");
        Console.WriteLine("{0,-35}{1,22}", "-----------", "-----");
        
        // Construct decimal objects from long values.
        CreateDecimal(Long.MIN_VALUE, "long.MinValue");
        CreateDecimal(Long.MAX_VALUE, "long.MaxValue");
        CreateDecimal(0L, "0");
        CreateDecimal(999999999999999999L, "999999999999999999");
        CreateDecimal(0x2000000000000000L, "0x2000000000000000");
        CreateDecimal((long)(0xE000000000000000L), "(long)0xE000000000000000");
    } //main
} //DecimalCtorLDemo

/*
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 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft