Decimal Constructor (UInt32)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

This API is not CLS-compliant. 

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

Syntax

'Declaration
<CLSCompliantAttribute(False)> _
Public Sub New ( _
    value As UInteger _
)
[CLSCompliantAttribute(false)]
public Decimal(
    uint value
)

Parameters

Examples

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( UInt32 ) constructor.

Module Example

   ' Create a Decimal object and display its value.
   Sub CreateDecimal(ByVal outputBlock As System.Windows.Controls.TextBlock, ByVal value As UInt32, ByVal valToStr As String)

      Dim decimalNum As New Decimal(value)

      ' Format the constructor for display.
      Dim ctor As String = _
          String.Format("Decimal( {0} )", valToStr)

      ' Display the constructor and its value.
      outputBlock.Text &= String.Format("{0,-33}{1,16}", ctor, decimalNum) & vbCrLf
   End Sub

   Public Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)

      outputBlock.Text &= _
          "This example of the Decimal( UInt32 ) constructor " & _
          vbCrLf & "generates the following output." & vbCrLf & vbCrLf
      outputBlock.Text &= String.Format("{0,-33}{1,16}", "Constructor", "Value") & vbCrLf
      outputBlock.Text &= String.Format("{0,-33}{1,16}", "-----------", "-----") & vbCrLf

      ' Construct Decimal objects from UInt32 values.
      ' UInt32.MinValue and UInt32.MaxValue are not defined in VB.
      CreateDecimal(outputBlock, Convert.ToUInt32(0), """UInt32.MinValue""")
      CreateDecimal(outputBlock, Convert.ToUInt32(4294967295), _
          """UInt32.MaxValue""")
      CreateDecimal(outputBlock, Convert.ToUInt32(Integer.MaxValue), _
          "Integer.MaxValue")
      CreateDecimal(outputBlock, Convert.ToUInt32(999999999), "999999999")
      CreateDecimal(outputBlock, Convert.ToUInt32(&H40000000), "&H40000000")
      CreateDecimal(outputBlock, Convert.ToUInt32(&HC0000000L), "&HC0000000")
   End Sub
End Module

' This example of the Decimal( UInt32 ) constructor
' generates the following output.
' 
' Constructor                                 Value
' -----------                                 -----
' Decimal( "UInt32.MinValue" )                    0
' Decimal( "UInt32.MaxValue" )           4294967295
' Decimal( Integer.MaxValue )            2147483647
' Decimal( 999999999 )                    999999999
' Decimal( &H40000000 )                  1073741824
' Decimal( &HC0000000 )                  3221225472
// Example of the decimal( uint ) constructor.
using System;

class Example
{
   // Create a decimal object and display its value.
   public static void CreateDecimal(System.Windows.Controls.TextBlock outputBlock, 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.
      outputBlock.Text += String.Format("{0,-33}{1,16}", ctor, decimalNum) + "\n";
   }

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

      // Construct decimal objects from uint values.
      CreateDecimal(outputBlock, uint.MinValue, "uint.MinValue");
      CreateDecimal(outputBlock, uint.MaxValue, "uint.MaxValue");
      CreateDecimal(outputBlock, (uint)int.MaxValue, "(uint)int.MaxValue");
      CreateDecimal(outputBlock, 999999999U, "999999999U");
      CreateDecimal(outputBlock, 0x40000000U, "0x40000000U");
      CreateDecimal(outputBlock, 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
*/

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.