Export (0) Print
Expand All

Decimal Constructor (UInt64)

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

This constructor is not CLS-compliant.  

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

[CLSCompliantAttribute(false)] 
public Decimal (
	ulong value
)
/** @attribute CLSCompliantAttribute(false) */ 
public Decimal (
	UInt64 value
)
CLSCompliantAttribute(false) 
public function Decimal (
	value : ulong
)

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 a UInt64 value.

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

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

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

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

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

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

class DecimalCtorLDemo
{   
    // Create a decimal object and display its value.
    public static void CreateDecimal(UInt64 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( ulong ) " 
            + "constructor \ngenerates the following output.\n"));
        Console.WriteLine("{0,-35}{1,22}", "Constructor", "Value");
        Console.WriteLine("{0,-35}{1,22}", "-----------", "-----");
        
        // Construct decimal objects from ulong values.
        //CreateDecimal(Long.MIN_VALUE, "ulong.MinValue");
        CreateDecimal(UInt64.MinValue, "ulong.MinValue");
        CreateDecimal(UInt64.MaxValue, "ulong.MaxValue");
        
        CreateDecimal(System.Convert.ToUInt64(Long.MAX_VALUE), "long.MaxValue");
        CreateDecimal(System.Convert.ToUInt64(999999999999999999L), 
            "999999999999999999" );
        CreateDecimal(System.Convert.ToUInt64(0x2000000000000000L), 
            "0x2000000000000000" );
        CreateDecimal((UInt64) 0xE000000000000000L, "0xE000000000000000" );
    } //main
} //DecimalCtorLDemo

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

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

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