C# Decimal Decimal(Int32, Int32, Int32, Boolean, Byte)

Description

Decimal Decimal(Int32, Int32, Int32, Boolean, Byte) initializes a new instance of Decimal from parameters specifying the instance's constituent parts.

Syntax

Decimal.Decimal(Int32, Int32, Int32, Boolean, Byte) has the following syntax.


public Decimal(/*from   ww  w.ja  v  a  2s.co  m*/
  int lo,
  int mid,
  int hi,
  bool isNegative,
  byte scale
)

Parameters

Decimal.Decimal(Int32, Int32, Int32, Boolean, Byte) has the following parameters.

  • lo - The low 32 bits of a 96-bit integer.
  • mid - The middle 32 bits of a 96-bit integer.
  • hi - The high 32 bits of a 96-bit integer.
  • isNegative - true to indicate a negative number; false to indicate a positive number.
  • scale - A power of 10 ranging from 0 to 28.

Example

The following code example creates several Decimal numbers using the constructor overload that initializes a Decimal structure with three Int32 value words, a Boolean sign, and a Byte scale factor.


using System;/*from  w ww .  j a  v  a 2 s.  co m*/

class DecimalCtorIIIBByDemo
{

    public static void Main( )
    {

            decimal decimalNum = new decimal( 
                1000000000, 0, 0, false, 0 );

    }
}

The code above generates the following result.

Example 2

The following example uses the GetBits method to retrieve the component parts of an array.

It then uses this array in the call to the Decimal(Int32, Int32, Int32, Boolean, Byte) constructor to instantiate a new Decimal value.


using System;/*from w ww . j  av a 2 s .c o  m*/

public class Example
{
   public static void Main()
   {
      Decimal[] values = { 1234.96m, -1234.96m };
      foreach (var value in values) {
         int[] parts = Decimal.GetBits(value);
         bool sign = (parts[3] & 0x80000000) != 0;

         byte scale = (byte) ((parts[3] >> 16) & 0x7F); 
         Decimal newValue = new Decimal(parts[0], parts[1], parts[2], sign, scale);
         Console.WriteLine("{0} --> {1}", value, newValue);
      }
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version