Export (0) Print
Expand All

Decimal Constructor (UInt32)

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

This constructor is not CLS-compliant.  

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

[CLSCompliantAttribute(false)] 
public Decimal (
	uint value
)
/** @attribute CLSCompliantAttribute(false) */ 
public Decimal (
	UInt32 value
)
CLSCompliantAttribute(false) 
public function Decimal (
	value : uint
)

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 UInt32 value.

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

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

        // Construct decimal objects from uint values.
        CreateDecimal( uint.MinValue, "uint.MinValue" );
        CreateDecimal( uint.MaxValue, "uint.MaxValue" );
        CreateDecimal( (uint)int.MaxValue, "(uint)int.MaxValue" );
        CreateDecimal( 999999999U, "999999999U" );
        CreateDecimal( 0x40000000U, "0x40000000U" );
        CreateDecimal( 0xC0000000, "0xC0000000" );
    }
}

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

Constructor                                 Value
-----------                                 -----
decimal( uint.MinValue )                        0
decimal( uint.MaxValue )               4294967295
decimal( (uint)int.MaxValue )          2147483647
decimal( 999999999U )                   999999999
decimal( 0x40000000U )                 1073741824
decimal( 0xC0000000 )                  3221225472
*/

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

class DecimalCtorUIDemo
{   
    // Create a decimal object and display its value.
    public static void CreateDecimal(UInt32 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,-33}{1,16}", ctor, decimalNum);
    } //CreateDecimal

    public static void main(String[] args)
    {
        Console.WriteLine(("This example of the decimal( uint ) "
            + "constructor \ngenerates the following output.\n"));
        Console.WriteLine("{0,-33}{1,16}", "Constructor", "Value");
        Console.WriteLine("{0,-33}{1,16}", "-----------", "-----");
        
        // Construct decimal objects from uint values.
        CreateDecimal(Convert.ToUInt32(UInt64.MinValue) , "uint.MinValue");
        CreateDecimal( UInt32.MaxValue, "uint.MaxValue");
        CreateDecimal(((UInt32) Int32.MaxValue), "(uint)int.MaxValue");
        CreateDecimal(Convert.ToUInt32(999999999), "999999999U");
        CreateDecimal(Convert.ToUInt32(0x40000000), "0x40000000U");
        CreateDecimal((UInt32)(0xC0000000), "0xC0000000");
        
    } //main
} //DecimalCtorUIDemo

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

Constructor                                 Value
-----------                                 -----
decimal( uint.MinValue )                        0
decimal( uint.MaxValue )               4294967295
decimal( (uint)int.MaxValue )          2147483647
decimal( 999999999U )                   999999999
decimal( 0x40000000U )                 1073741824
decimal( 0xC0000000 )                  3221225472
*/

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