Decimal Constructor (Int32)

May 11, 2014

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

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

'Declaration
Public Sub New ( _
	value As Integer _
)

Parameters

value
Type: System.Int32
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 Int32 value.


' Example of the Decimal( Integer ) constructor.

Module Example

   ' Create a Decimal object and display its value.
   Sub CreateDecimal(ByVal outputBlock As System.Windows.Controls.TextBlock, ByVal value As Integer, 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( Integer ) 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 Integer values.
      CreateDecimal(outputBlock, Integer.MinValue, "Integer.MinValue")
      CreateDecimal(outputBlock, Integer.MaxValue, "Integer.MaxValue")
      CreateDecimal(outputBlock, 0, "0")
      CreateDecimal(outputBlock, 999999999, "999999999")
      CreateDecimal(outputBlock, &H40000000, "&H40000000")
      CreateDecimal(outputBlock, &HC0000000, "&HC0000000")
   End Sub
End Module

' This example of the Decimal( Integer ) constructor
' generates the following output.
' 
' Constructor                                 Value
' -----------                                 -----
' Decimal( Integer.MinValue )           -2147483648
' Decimal( Integer.MaxValue )            2147483647
' Decimal( 0 )                                    0
' Decimal( 999999999 )                    999999999
' Decimal( &H40000000 )                  1073741824
' Decimal( &HC0000000 )                 -1073741824


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft