System.Decimal Structure

Assembly: Mscorlib.dll
Namespace: System
Summary
Represents a decimal number.
C# Syntax:
[Serializable]
public struct Decimal : IFormattable, IComparable, IConvertible
Thread Safety
This type is safe for multithreaded operations.
Remarks
The Decimal value type represents decimal numbers ranging from positive 79,228,162,514,264,337,593,543,950,335 to negative 79,228,162,514,264,337,593,543,950,335. The Decimal value type is appropriate for financial calculations requiring large numbers of significant integral and fractional digits and no round-off errors.

A decimal number is a signed, fixed-point value consisting of an integral part and an optional fractional part. The integral and fractional parts consist of a series of digits that range from zero to nine (0 to 9), separated by a decimal point symbol.

The binary representation of an instance of Decimal consists of a 1-bit sign, a 96-bit integer number, and a scaling factor used to divide the 96-bit integer and specify what portion of it is a decimal fraction. The scaling factor is implicitly the number 10, raised to an exponent ranging from 0 to 28.

Therefore, the binary representation of a Decimal value is of the form, ((-2 96 to 2 96) / 10 (0 to 28)), where -2 96 is equal to Decimal.MinValue, and 2 96 is equal to Decimal.MaxValue.

This type provides methods that convert Decimal values to and from type Char, SByte, Int16, Int32, Int64, Byte, UInt16, UInt32, and UInt64. Conversions from other types to Decimal are widening conversions that never lose information or throw exceptions.

Conversions from Decimal to other types are narrowing conversions that round the Decimal value to the nearest integer value toward zero. If the result of the conversion is not representable in the destination type, an OverflowException is thrown.

This type provides methods that convert Decimal values to and from Single and Double. Conversions from Decimal to Single or Double are narrowing conversions that might lose precision but not information about the magnitude of the converted value. The conversion will not throw an exception.

Conversions from Single or Double to Decimal throw an OverflowException if the result of the conversion is not representable as a Decimal.

This type implements interfaces IComparable, IFormattable, and IConvertible. Use the Convert class for conversions instead of this type's explicit interface member implementation of IConvertible.

See also:
System Namespace | SByte | Int16 | Int32 | Int64 | Byte | UInt16 | UInt32 | UInt64 | Single | Double | Char

System.Decimal Member List:

Public Constructors
ctor #1 Overloaded:
.ctor(double value)

Initializes a new instance of Decimal to the value of the specified double-precision floating-point number.
ctor #2 Overloaded:
.ctor(int value)

Initializes a new instance of Decimal to the value of the specified 32-bit signed integer.
ctor #3 Overloaded:
.ctor(int[] bits)

Initializes a new instance of Decimal to a decimal value represented in binary and contained in a specified array.
ctor #4 Overloaded:
.ctor(long value)

Initializes a new instance of Decimal to the value of the specified 64-bit signed integer.
ctor #5 Overloaded:
.ctor(float value)

Initializes a new instance of Decimal to the value of the specified single-precision floating-point number.
ctor #6 Overloaded:
.ctor(uint value)

Initializes a new instance of Decimal to the value of the specified 32-bit unsigned integer.
ctor #7 Overloaded:
.ctor(ulong value)

Initializes a new instance of Decimal to the value of the specified 64-bit unsigned integer.
ctor #8 Overloaded:
.ctor(int lo, int mid, int hi, bool isNegative, byte scale)

Initializes a new instance of Decimal from parameters specifying the instance's constituent parts.
Public Fields
MaxValue Represents the largest possible value of Decimal. This field is constant and read-only.
MinusOne
MinValue Represents the smallest possible value of Decimal. This field is constant and read-only.
One
Zero Represents the number zero (0).
Public Methods
Add Adds two specified Decimal values.
Compare Compares two specified Decimal values.
CompareTo Compares this instance to a specified Object.
Divide Divides two specified Decimal values.
Equals Overloaded:
Equals(object value)

Overridden:
Returns a value indicating whether this instance and a specified Object represent the same type and value.
Equals Overloaded:
Equals(decimal d1, decimal d2)

Returns a value indicating whether two specified instances of Decimal represent the same value.
Floor Rounds a specified Decimal number to the closest integer toward negative infinity.
FromOACurrency Converts the specified 64-bit signed integer, which contains an OLE Automation Currency value, to the equivalent Decimal value.
GetBits Converts the value of a specified instance of Decimal to its equivalent binary representation.
GetHashCode Overridden:
Returns the hash code for this instance.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
GetTypeCode Returns the TypeCode for value type Decimal.
Multiply Multiplies two specified Decimal values.
Negate Returns the result of multiplying the specified Decimal value by negative one.
Parse Overloaded:
Parse(string s)

Converts the String representation of a number to its Decimal equivalent.
Parse Overloaded:
Parse(string s, IFormatProvider provider)

Converts the String representation of a number to its Decimal equivalent using the specified culture-specific format information.
Parse Overloaded:
Parse(string s, NumberStyles style)

Converts the String representation of a number in a specified style to its Decimal equivalent using the specified formatting style.
Parse Overloaded:
Parse(string s, NumberStyles style, IFormatProvider provider)

Converts the String representation of a number to its Decimal equivalent using the specified style and culture-specific format.
Remainder Computes the remainder after dividing two Decimal values.
Round Rounds a Decimal value to a specified number of decimal places.
Subtract Subtracts one specified Decimal value from another.
ToByte Converts the value of the specified Decimal to the equivalent 8-bit unsigned integer.
ToDouble Converts the value of the specified Decimal to the equivalent double-precision floating-point number.
ToInt16 Converts the value of the specified Decimal to the equivalent 16-bit signed integer.
ToInt32 Converts the value of the specified Decimal to the equivalent 32-bit signed integer.
ToInt64 Converts the value of the specified Decimal to the equivalent 64-bit signed integer.
ToOACurrency Converts the specified Decimal value to the equivalent OLE Automation Currency value, which is contained in a 64-bit signed integer.
ToSByte Converts the value of the specified Decimal to the equivalent 8-bit signed integer.
ToSingle Converts the value of the specified Decimal to the equivalent single-precision floating-point number.
ToString Overloaded:
ToString()

Overridden:
Converts the numeric value of this instance to its equivalent String representation.
ToString Overloaded:
ToString(IFormatProvider provider)

Converts the numeric value of this instance to its equivalent String representation using the specified culture-specific format information.
ToString Overloaded:
ToString(string format)

Converts the numeric value of this instance to its equivalent String representation, using the specified format.
ToString Overloaded:
ToString(string format, IFormatProvider provider)

Converts the numeric value of this instance to its equivalent String representation using the specified format and culture-specific format information.
ToUInt16 Converts the value of the specified Decimal to the equivalent 16-bit unsigned integer.
ToUInt32 Converts the value of the specified Decimal to the equivalent 32-bit unsigned integer.
ToUInt64 Converts the value of the specified Decimal to the equivalent 64-bit unsigned integer.
Truncate Returns the integral digits of the specified Decimal; any fractional digits are discarded.
Public Operators and Type Conversions
op_Addition Adds two specified Decimal values.
op_Decrement Decrements the Decimal operand by one.
op_Division Divides two specified Decimal values.
op_Equality Returns a value indicating whether two instances of Decimal are equal.
op_Explicit
(convert System.Decimal to System.Char)
Overloaded:
op_Explicit(decimal value)

Converts a Decimal to a Unicode character.
op_Explicit
(convert System.Decimal to System.Int64)
Overloaded:
op_Explicit(decimal value)

Converts a Decimal to a 64-bit signed integer.
op_Explicit
(convert System.Decimal to System.UInt32)
Overloaded:
op_Explicit(decimal value)

Converts a Decimal to a 32-bit unsigned integer.
op_Explicit
(convert System.Decimal to System.Int32)
Overloaded:
op_Explicit(decimal value)

Converts a Decimal to a 32-bit signed integer.
op_Explicit
(convert System.Decimal to System.UInt16)
Overloaded:
op_Explicit(decimal value)

Converts a Decimal to a 16-bit unsigned integer.
op_Explicit
(convert System.Decimal to System.Int16)
Overloaded:
op_Explicit(decimal value)

Converts a Decimal to a 16-bit signed integer.
op_Explicit
(convert System.Decimal to System.SByte)
Overloaded:
op_Explicit(decimal value)

Converts a Decimal to an 8-bit signed integer.
op_Explicit
(convert System.Decimal to System.Single)
Overloaded:
op_Explicit(decimal value)

Converts a Decimal to a single-precision floating-point number.
op_Explicit
(convert System.Decimal to System.Double)
Overloaded:
op_Explicit(decimal value)

Converts a Decimal to a double-precision floating-point number.
op_Explicit
(convert System.Decimal to System.UInt64)
Overloaded:
op_Explicit(decimal value)

Converts a Decimal to a 64-bit unsigned integer.
op_Explicit
(convert System.Decimal to System.Byte)
Overloaded:
op_Explicit(decimal value)

Converts a Decimal to an 8-bit unsigned integer.
op_Explicit
(convert System.Double to System.Decimal)
Overloaded:
op_Explicit(double value)

Converts a double-precision floating-point number to a Decimal.
op_Explicit
(convert System.Single to System.Decimal)
Overloaded:
op_Explicit(float value)

Converts a single-precision floating-point number to a Decimal.
op_GreaterThan Returns a value indicating whether a specified Decimal is greater than another specified Decimal.
op_GreaterThanOrEqual Returns a value indicating whether a specified Decimal is greater than or equal to another specified Decimal.
op_Implicit
(convert System.Byte to System.Decimal)
Overloaded:
op_Implicit(byte value)

Converts an 8-bit unsigned integer to a Decimal.
op_Implicit
(convert System.Char to System.Decimal)
Overloaded:
op_Implicit(char value)

Converts a Unicode character to a Decimal.
op_Implicit
(convert System.Int16 to System.Decimal)
Overloaded:
op_Implicit(short value)

Converts a 16-bit signed integer to a Decimal.
op_Implicit
(convert System.Int32 to System.Decimal)
Overloaded:
op_Implicit(int value)

Converts a 32-bit signed integer to a Decimal.
op_Implicit
(convert System.Int64 to System.Decimal)
Overloaded:
op_Implicit(long value)

Converts a 64-bit signed integer to a Decimal.
op_Implicit
(convert System.SByte to System.Decimal)
Overloaded:
op_Implicit(sbyte value)

Converts an 8-bit signed integer to a Decimal.
op_Implicit
(convert System.UInt16 to System.Decimal)
Overloaded:
op_Implicit(ushort value)

Converts a 16-bit unsigned integer to a Decimal.
op_Implicit
(convert System.UInt32 to System.Decimal)
Overloaded:
op_Implicit(uint value)

Converts a 32-bit unsigned integer to a Decimal.
op_Implicit
(convert System.UInt64 to System.Decimal)
Overloaded:
op_Implicit(ulong value)

Converts a 64-bit unsigned integer to a Decimal.
op_Increment Increments the Decimal operand by 1.
op_Inequality Returns a value indicating whether two instances of Decimal are not equal.
op_LessThan Returns a value indicating whether a specified Decimal is less than another specified Decimal.
op_LessThanOrEqual Returns a value indicating whether a specified Decimal is less than or equal to another specified Decimal.
op_Modulus Returns the remainder resulting from dividing two specified Decimal values.
op_Multiply Multiplies two specified Decimal values.
op_Subtraction Subtracts two specified Decimal values.
op_UnaryNegation Negates the value of the specified Decimal operand.
op_UnaryPlus Returns the value of the Decimal operand (the sign of the operand is unchanged).
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Decimal Member Details

Overloaded ctor #1
Summary
Initializes a new instance of Decimal to the value of the specified double-precision floating-point number.
C# Syntax:
public Decimal(
   double value
);
Parameters:

value

The value to represent as a Decimal.

Exceptions
Exception Type Condition
OverflowException value is greater than Decimal.MaxValue or less than Decimal.MinValue.

-or-

value is Double.NaN, Double.PositiveInfinity, or Double.NegativeInfinity.

Remarks
This constructor rounds value to 15 significant digits using rounding to nearest. This is done even if the number has more than 15 digits and the less significant digits are zero.

Return to top


Overloaded ctor #2
Summary
Initializes a new instance of Decimal to the value of the specified 32-bit signed integer.
C# Syntax:
public Decimal(
   int value
);
Parameters:

value

The value to represent as a Decimal.

Return to top


Overloaded ctor #3
Summary
Initializes a new instance of Decimal to a decimal value represented in binary and contained in a specified array.
C# Syntax:
public Decimal(
   int[] bits
);
Parameters:

bits

An array of 32-bit signed integers containing a representation of a decimal value.

Exceptions
Exception Type Condition
ArgumentNullException bits is null.
ArgumentException The length of the bits is not 4.

-or-

The representation of the decimal value in bits is not valid.

Remarks
The binary representation of a Decimal number consists of a 1-bit sign, a 96-bit integer number, and a scaling factor used to divide the integer number and specify what portion of it is a decimal fraction. The scaling factor is implicitly the number 10, raised to an exponent ranging from 0 to 28.

bits is a four-element long array of 32-bit signed integers.

bits [0], bits [1], and bits [2] contain the low, middle, and high 32 bits of the 96-bit integer number.

bits [3] contains the scale factor and sign, and consists of following parts:

Bits 0 to 15, the lower word, are unused and must be zero.

Bits 16 to 23 must contain an exponent between 0 and 28, that indicates the power of 10 to divide the integer number.

Bits 24 to 30 are unused and must be zero.

Bit 31 contains the sign; 0 meaning positive, and 1 meaning negative.

A numeric value might have several possible binary representations; all are equally valid and numerically equivalent. Note that the bit representation differentiates between negative and positive zero. These values are treated as being equal in all operations.

See also:
Decimal.GetBits

Return to top


Overloaded ctor #4
Summary
Initializes a new instance of Decimal to the value of the specified 64-bit signed integer.
C# Syntax:
public Decimal(
   long value
);
Parameters:

value

The value to represent as a Decimal.

Return to top


Overloaded ctor #5
Summary
Initializes a new instance of Decimal to the value of the specified single-precision floating-point number.
C# Syntax:
public Decimal(
   float value
);
Parameters:

value

The value to represent as a Decimal.

Exceptions
Exception Type Condition
OverflowException value is greater than Decimal.MaxValue or less than Decimal.MinValue.

-or-

value is Single.NaN, Single.PositiveInfinity, or Single.NegativeInfinity.

Remarks
This constructor rounds value to 7 significant digits using rounding to nearest. This is done even if the number has more than 7 digits and the less significant digits are zero.

Return to top


Overloaded ctor #6
Summary
Initializes a new instance of Decimal to the value of the specified 32-bit unsigned integer.
This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
public Decimal(
   uint value
);
Parameters:

value

The value to represent as a Decimal.

Return to top


Overloaded ctor #7
Summary
Initializes a new instance of Decimal to the value of the specified 64-bit unsigned integer.
This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
public Decimal(
   ulong value
);
Parameters:

value

The value to represent as a Decimal.

Return to top


Overloaded ctor #8
Summary
Initializes a new instance of Decimal from parameters specifying the instance's constituent parts.
C# Syntax:
public Decimal(
   int lo,
   int mid,
   int hi,
   bool isNegative,
   byte scale
);
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

The sign of the number; 1 is negative, 0 is positive.

scale

A power of 10 ranging from 0 to 28.

Exceptions
Exception Type Condition
ArgumentOutOfRangeException scale is greater than 28.
Remarks
The binary representation of a Decimal number consists of a 1-bit sign, a 96-bit integer number, and a scaling factor used to divide the integer number and specify what portion of it is a decimal fraction. The scaling factor is implicitly the number 10 raised to an exponent ranging from 0 to 28.

Return to top


Field: MaxValue
Summary
Represents the largest possible value of Decimal. This field is constant and read-only.
C# Syntax:
public static readonly decimal MaxValue;
Remarks
The value of this constant is positive 79,228,162,514,264,337,593,543,950,335.
See also:
Decimal.Zero | Decimal.One | Decimal.MinusOne | Decimal.MinValue

Return to top


Field: MinusOne
Summary
Represents the number negative one (-1).
C# Syntax:
public static readonly decimal MinusOne;
See also:
Decimal.Zero | Decimal.One | Decimal.MaxValue | Decimal.MinValue

Return to top


Field: MinValue
Summary
Represents the smallest possible value of Decimal. This field is constant and read-only.
C# Syntax:
public static readonly decimal MinValue;
Remarks
The value of this constant is negative 79,228,162,514,264,337,593,543,950,335.
See also:
Decimal.Zero | Decimal.One | Decimal.MinusOne | Decimal.MaxValue

Return to top


Field: One
Summary
Represents the number one (1).
C# Syntax:
public static readonly decimal One;
See also:
Decimal.Zero | Decimal.MinusOne | Decimal.MaxValue | Decimal.MinValue

Return to top


Field: Zero
Summary
Represents the number zero (0).
C# Syntax:
public static readonly decimal Zero;
See also:
Decimal.One | Decimal.MinusOne | Decimal.MaxValue | Decimal.MinValue

Return to top


Method: Add(
   decimal d1,
   decimal d2
)
Summary
Adds two specified Decimal values.
C# Syntax:
public static decimal Add(
   decimal d1,
   decimal d2
);
Parameters:

d1

A Decimal.

d2

A Decimal.

Return Value:
A Decimal value that is the sum of d1 and d2.
Exceptions
Exception Type Condition
OverflowException The sum of d1 and d2 is less than Decimal.MinValue or greater than Decimal.MaxValue.
See also:
Decimal.Subtract | Decimal.Multiply | Decimal.Divide

Return to top


Method: Compare(
   decimal d1,
   decimal d2
)
Summary
Compares two specified Decimal values.
C# Syntax:
public static int Compare(
   decimal d1,
   decimal d2
);
Parameters:

d1

A Decimal.

d2

A Decimal.

Return Value:
A signed number indicating the relative values of d1 and d2.

Return Value Meaning
Less than zero is less than .
Zero and are equal.
Greater than zero is greater than .
See also:
Decimal.CompareTo | Decimal.Equals

Return to top


Method: CompareTo(
   object value
)
Summary
Compares this instance to a specified Object.
C# Syntax:
public int CompareTo(
   object value
);
Parameters:

value

An Object or null.

Return Value:
A signed number indicating the relative values of this instance and value.

Return Value Meaning
Less than zero This instance is less than .
Zero This instance is equal to .
Greater than zero This instance is greater than value. -or- value is null.
Exceptions
Exception Type Condition
ArgumentException value is not a Decimal or null.
Remarks
Any instance of Decimal, regardless of its value, is considered greater than null.

Parameter value must be null or an instance of Decimal; otherwise, an exception is thrown.

See also:
Decimal.Compare | Decimal.Equals

Return to top


Method: Divide(
   decimal d1,
   decimal d2
)
Summary
Divides two specified Decimal values.
C# Syntax:
public static decimal Divide(
   decimal d1,
   decimal d2
);
Parameters:

d1

A Decimal (the dividend).

d2

A Decimal (the divisor).

Return Value:
The Decimal that is the result of dividing d1 by d2.
Exceptions
Exception Type Condition
DivideByZeroException d2 is zero.
OverflowException The return value (that is, the quotient) is less than Decimal.MinValue or greater than Decimal.MaxValue.
See also:
Decimal.Add | Decimal.Subtract | Decimal.Multiply

Return to top


Overloaded Method: Equals(
   object value
)
Summary
Returns a value indicating whether this instance and a specified Object represent the same type and value.
C# Syntax:
public override bool Equals(
   object value
);
Parameters:

value

An Object.

Return Value:
true if value is a Decimal and equal to this instance; otherwise, false.
See also:
Decimal.Compare | Decimal.CompareTo

Return to top


Overloaded Method: Equals(
   decimal d1,
   decimal d2
)
Summary
Returns a value indicating whether two specified instances of Decimal represent the same value.
C# Syntax:
public static bool Equals(
   decimal d1,
   decimal d2
);
Parameters:

d1

A Decimal.

d2

A Decimal.

Return Value:
true if d1 and d2 are equal; otherwise, false.
See also:
Decimal.Compare | Decimal.CompareTo

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~Decimal();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Floor(
   decimal d
)
Summary
Rounds a specified Decimal number to the closest integer toward negative infinity.
C# Syntax:
public static decimal Floor(
   decimal d
);
Parameters:

d

A Decimal.

Return Value:
If d has a fractional part, the next whole Decimal number toward negative infinity that is less than d.

-or-

If d doesn't have a fractional part, d is returned unchanged.

See also:
Decimal.Round | Decimal.Truncate

Return to top


Method: FromOACurrency(
   long cy
)
Summary
Converts the specified 64-bit signed integer, which contains an OLE Automation Currency value, to the equivalent Decimal value.
C# Syntax:
public static decimal FromOACurrency(
   long cy
);
Parameters:

cy

An OLE Automation Currency value.

Return Value:
A Decimal that contains the equivalent of cy.
See also:
Decimal.ToOACurrency

Return to top


Method: GetBits(
   decimal d
)
Summary
Converts the value of a specified instance of Decimal to its equivalent binary representation.
C# Syntax:
public static int[] GetBits(
   decimal d
);
Parameters:

d

A Decimal value.

Return Value:
A 32-bit signed integer array with four elements that contain the binary representation of d.
Remarks
The binary representation of a Decimal number consists of a 1-bit sign, a 96-bit integer number, and a scaling factor used to divide the integer number and specify what portion of it is a decimal fraction. The scaling factor is implicitly the number 10, raised to an exponent ranging from 0 to 28.

The return value is a four-element long array of 32-bit signed integers.

The first, second, and third elements of the returned array contain the low, middle, and high 32 bits of the 96-bit integer number.

The fourth element of the returned array contains the scale factor and sign. It consists of the following parts:

Bits 0 to 15, the lower word, are unused and must be zero.

Bits 16 to 23 must contain an exponent between 0 and 28, that indicates the power of 10 to divide the integer number.

Bits 24 to 30 are unused and must be zero.

Bit 31 contains the sign; 0 meaning positive, and 1 meaning negative.

Note that the bit representation differentiates between negative and positive zero. These values are treated as being equal in all operations.

See also:
Decimal.#ctor

Return to top


Overridden Method: GetHashCode()
Summary
Returns the hash code for this instance.
C# Syntax:
public override int GetHashCode();
Return Value:
A 32-bit signed integer hash code.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetTypeCode()
Summary
Returns the TypeCode for value type Decimal.
C# Syntax:
public TypeCode GetTypeCode();
Return Value:
The enumerated constant TypeCode.Decimal.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Multiply(
   decimal d1,
   decimal d2
)
Summary
Multiplies two specified Decimal values.
C# Syntax:
public static decimal Multiply(
   decimal d1,
   decimal d2
);
Parameters:

d1

A Decimal (the multiplicand).

d2

A Decimal (the multiplier).

Return Value:
A Decimal that is the result of multiplying d1 and d2.
Exceptions
Exception Type Condition
OverflowException The return value is less than Decimal.MinValue or greater than Decimal.MaxValue.
See also:
Decimal.Add | Decimal.Subtract | Decimal.Divide

Return to top


Method: Negate(
   decimal d
)
Summary
Returns the result of multiplying the specified Decimal value by negative one.
C# Syntax:
public static decimal Negate(
   decimal d
);
Parameters:

d

A Decimal.

Return Value:
A Decimal with the value of d, but the opposite sign.

-or-

Zero, if d is zero.

Return to top


Method: op_Addition(
   decimal d1,
   decimal d2
)
Summary
Adds two specified Decimal values.
C# Syntax:
public static decimal operator +(
   decimal d1,
   decimal d2
);
Parameters:

d1

A Decimal.

d2

A Decimal.

Return Value:
The Decimal result of adding d1 and d2.
Exceptions
Exception Type Condition
OverflowException The return value is less than Decimal.MinValue or greater than Decimal.MaxValue.
See also:
Decimal.Add

Return to top


Method: op_Decrement(
   decimal d
)
Summary
Decrements the Decimal operand by one.
C# Syntax:
public static decimal operator --(
   decimal d
);
Parameters:

d

The Decimal operand.

Return Value:
The value of d decremented by 1.
Exceptions
Exception Type Condition
OverflowException The return value is less than Decimal.MinValue or greater than Decimal.MaxValue.
See also:
Decimal.Subtract

Return to top


Method: op_Division(
   decimal d1,
   decimal d2
)
Summary
Divides two specified Decimal values.
C# Syntax:
public static decimal operator /(
   decimal d1,
   decimal d2
);
Parameters:

d1

A Decimal (the dividend).

d2

A Decimal (the divisor).

Return Value:
The Decimal result of d1 by d2.
Exceptions
Exception Type Condition
DivideByZeroException d2 is zero.
OverflowException The return value is less than Decimal.MinValue or greater than Decimal.MaxValue.
See also:
Decimal.Divide

Return to top


Method: op_Equality(
   decimal d1,
   decimal d2
)
Summary
Returns a value indicating whether two instances of Decimal are equal.
C# Syntax:
public static bool operator ==(
   decimal d1,
   decimal d2
);
Parameters:

d1

A Decimal.

d2

A Decimal.

Return Value:
true if d1 and d2 are equal; otherwise, false.
See also:
Decimal.Compare | Decimal.Equals

Return to top


Overloaded Method: op_Explicit System.Char(
   decimal value
)
Summary
Converts a Decimal to a Unicode character.
C# Syntax:
public static operator explicit char(
   decimal value
);
Parameters:

value

A Decimal to convert.

Return Value:
A Unicode character that represents the converted Decimal.
Exceptions
Exception Type Condition
OverflowException value is less than Int16.MinValue or greater than Int16.MaxValue.
See also:
Char

Return to top


Overloaded Method: op_Explicit System.Int64(
   decimal value
)
Summary
Converts a Decimal to a 64-bit signed integer.
C# Syntax:
public static operator explicit long(
   decimal value
);
Parameters:

value

A Decimal to convert.

Return Value:
A 64-bit signed integer that represents the converted Decimal.
Exceptions
Exception Type Condition
OverflowException value is less than Int64.MinValue or greater than Int64.MaxValue.
See also:
Int64

Return to top


Overloaded Method: op_Explicit System.UInt32(
   decimal value
)
Summary
Converts a Decimal to a 32-bit unsigned integer.
This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
public static operator explicit uint(
   decimal value
);
Parameters:

value

A Decimal to convert.

Return Value:
A 32-bit unsigned integer that represents the converted Decimal.
Exceptions
Exception Type Condition
OverflowException value is negative or greater than UInt32.MaxValue.
See also:
UInt32

Return to top


Overloaded Method: op_Explicit System.Int32(
   decimal value
)
Summary
Converts a Decimal to a 32-bit signed integer.
C# Syntax:
public static operator explicit int(
   decimal value
);
Parameters:

value

A Decimal to convert.

Return Value:
A 32-bit signed integer that represents the converted Decimal.
Exceptions
Exception Type Condition
OverflowException value is less than Int32.MinValue or greater than Int32.MaxValue.
See also:
Int32

Return to top


Overloaded Method: op_Explicit System.UInt16(
   decimal value
)
Summary
Converts a Decimal to a 16-bit unsigned integer.
This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
public static operator explicit ushort(
   decimal value
);
Parameters:

value

A Decimal to convert.

Return Value:
A 16-bit unsigned integer that represents the converted Decimal.
Exceptions
Exception Type Condition
OverflowException value is greater than UInt16.MaxValue or less than UInt16.MinValue.
See also:
UInt16

Return to top


Overloaded Method: op_Explicit System.Int16(
   decimal value
)
Summary
Converts a Decimal to a 16-bit signed integer.
C# Syntax:
public static operator explicit short(
   decimal value
);
Parameters:

value

A Decimal to convert.

Return Value:
A 16-bit signed integer that represents the converted Decimal.
Exceptions
Exception Type Condition
OverflowException value is less than Int16.MinValue or greater than Int16.MaxValue.
See also:
Int16

Return to top


Overloaded Method: op_Explicit System.SByte(
   decimal value
)
Summary
Converts a Decimal to an 8-bit signed integer.
This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
public static operator explicit sbyte(
   decimal value
);
Parameters:

value

A Decimal to convert.

Return Value:
An 8-bit signed integer that represents the converted Decimal.
Exceptions
Exception Type Condition
OverflowException value is less than SByte.MinValue or greater than SByte.MaxValue.
See also:
SByte

Return to top


Overloaded Method: op_Explicit System.Single(
   decimal value
)
Summary
Converts a Decimal to a single-precision floating-point number.
C# Syntax:
public static operator explicit float(
   decimal value
);
Parameters:

value

A Decimal to convert.

Return Value:
A single-precision floating-point number that represents the converted Decimal.
Remarks
This operation can produce round-off errors because a single-precision floating-point number has fewer significant digits than a Decimal.
See also:
Single

Return to top


Overloaded Method: op_Explicit System.Double(
   decimal value
)
Summary
Converts a Decimal to a double-precision floating-point number.
C# Syntax:
public static operator explicit double(
   decimal value
);
Parameters:

value

A Decimal to convert.

Return Value:
A double-precision floating-point number that represents the converted Decimal.
Remarks
This operation can produce round-off errors because a double-precision floating-point number has fewer significant digits than a Decimal.
See also:
Double

Return to top


Overloaded Method: op_Explicit System.UInt64(
   decimal value
)
Summary
Converts a Decimal to a 64-bit unsigned integer.
This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
public static operator explicit ulong(
   decimal value
);
Parameters:

value

A Decimal to convert.

Return Value:
A 64-bit unsigned integer that represents the converted Decimal.
Exceptions
Exception Type Condition
OverflowException value is negative or greater than UInt64.MaxValue.
See also:
UInt64

Return to top


Overloaded Method: op_Explicit System.Byte(
   decimal value
)
Summary
Converts a Decimal to an 8-bit unsigned integer.
C# Syntax:
public static operator explicit byte(
   decimal value
);
Parameters:

value

A Decimal to convert.

Return Value:
An 8-bit unsigned integer that represents the converted Decimal.
Exceptions
Exception Type Condition
OverflowException value is less than Byte.MinValue or greater than Byte.MaxValue.
See also:
Byte

Return to top


Overloaded Method: op_Explicit System.Decimal(
   double value
)
Summary
Converts a double-precision floating-point number to a Decimal.
C# Syntax:
public static operator explicit decimal(
   double value
);
Parameters:

value

A double-precision floating-point number.

Return Value:
A Decimal that represents the converted double-precision floating point number.
Exceptions
Exception Type Condition
OverflowException value is less than Decimal.MinValue or greater than Decimal.MaxValue.

-or-

value is Double.NaN, Double.PositiveInfinity, or Double.NegativeInfinity.

See also:
Double

Return to top


Overloaded Method: op_Explicit System.Decimal(
   float value
)
Summary
Converts a single-precision floating-point number to a Decimal.
C# Syntax:
public static operator explicit decimal(
   float value
);
Parameters:

value

A single-precision floating-point number.

Return Value:
A Decimal that represents the converted single-precision floating point number.
Exceptions
Exception Type Condition
OverflowException value is less than Decimal.MinValue or greater than Decimal.MaxValue.

-or-

value is Single.NaN, Single.PositiveInfinity, or Single.NegativeInfinity.

See also:
Single

Return to top


Method: op_GreaterThan(
   decimal d1,
   decimal d2
)
Summary
Returns a value indicating whether a specified Decimal is greater than another specified Decimal.
C# Syntax:
public static bool operator >(
   decimal d1,
   decimal d2
);
Parameters:

d1

A Decimal.

d2

A Decimal.

Return Value:
true if d1 is greater than d2; otherwise, false.
See also:
Decimal.Compare

Return to top


Method: op_GreaterThanOrEqual(
   decimal d1,
   decimal d2
)
Summary
Returns a value indicating whether a specified Decimal is greater than or equal to another specified Decimal.
C# Syntax:
public static bool operator >=(
   decimal d1,
   decimal d2
);
Parameters:

d1

A Decimal.

d2

A Decimal.

Return Value:
true if d1 is greater than or equal to d2; otherwise, false.
See also:
Decimal.Compare

Return to top


Overloaded Method: op_Implicit System.Decimal(
   byte value
)
Summary
Converts an 8-bit unsigned integer to a Decimal.
C# Syntax:
public static operator implicit decimal(
   byte value
);
Parameters:

value

An 8-bit unsigned integer.

Return Value:
A Decimal that represents the converted 8-bit unsigned integer.
See also:
Byte

Return to top


Overloaded Method: op_Implicit System.Decimal(
   char value
)
Summary
Converts a Unicode character to a Decimal.
C# Syntax:
public static operator implicit decimal(
   char value
);
Parameters:

value

A Unicode character.

Return Value:
A Decimal that represents the converted Unicode character.
See also:
Char

Return to top


Overloaded Method: op_Implicit System.Decimal(
   short value
)
Summary
Converts a 16-bit signed integer to a Decimal.
C# Syntax:
public static operator implicit decimal(
   short value
);
Parameters:

value

A 16-bit signed integer.

Return Value:
A Decimal that represents the converted 16-bit signed integer.
See also:
Int16

Return to top


Overloaded Method: op_Implicit System.Decimal(
   int value
)
Summary
Converts a 32-bit signed integer to a Decimal.
C# Syntax:
public static operator implicit decimal(
   int value
);
Parameters:

value

A 32-bit signed integer.

Return Value:
A Decimal that represents the converted 32-bit signed integer.
See also:
Int32

Return to top


Overloaded Method: op_Implicit System.Decimal(
   long value
)
Summary
Converts a 64-bit signed integer to a Decimal.
C# Syntax:
public static operator implicit decimal(
   long value
);
Parameters:

value

A 64-bit signed integer.

Return Value:
A Decimal that represents the converted 64-bit signed integer.
See also:
Int64

Return to top


Overloaded Method: op_Implicit System.Decimal(
   sbyte value
)
Summary
Converts an 8-bit signed integer to a Decimal.
This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
public static operator implicit decimal(
   sbyte value
);
Parameters:

value

An 8-bit signed integer.

Return Value:
A Decimal that represents the converted 8-bit signed integer.
See also:
SByte

Return to top


Overloaded Method: op_Implicit System.Decimal(
   ushort value
)
Summary
Converts a 16-bit unsigned integer to a Decimal.
This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
public static operator implicit decimal(
   ushort value
);
Parameters:

value

A 16-bit unsigned integer.

Return Value:
A Decimal that represents the converted 16-bit unsigned integer.
See also:
UInt16

Return to top


Overloaded Method: op_Implicit System.Decimal(
   uint value
)
Summary
Converts a 32-bit unsigned integer to a Decimal.
This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
public static operator implicit decimal(
   uint value
);
Parameters:

value

A 32-bit unsigned integer.

Return Value:
A Decimal that represents the converted 32-bit unsigned integer.
See also:
UInt32

Return to top


Overloaded Method: op_Implicit System.Decimal(
   ulong value
)
Summary
Converts a 64-bit unsigned integer to a Decimal.
This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
public static operator implicit decimal(
   ulong value
);
Parameters:

value

A 64-bit unsigned integer.

Return Value:
A Decimal that represents the converted 64-bit unsigned integer.
See also:
UInt64

Return to top


Method: op_Increment(
   decimal d
)
Summary
Increments the Decimal operand by 1.
C# Syntax:
public static decimal operator ++(
   decimal d
);
Parameters:

d

The Decimal operand.

Return Value:
The value of d incremented by 1.
Exceptions
Exception Type Condition
OverflowException The return value is less than Decimal.MinValue or greater than Decimal.MaxValue.
See also:
Decimal.Add

Return to top


Method: op_Inequality(
   decimal d1,
   decimal d2
)
Summary
Returns a value indicating whether two instances of Decimal are not equal.
C# Syntax:
public static bool operator !=(
   decimal d1,
   decimal d2
);
Parameters:

d1

A Decimal.

d2

A Decimal.

Return Value:
true if d1 and d2 are not equal; otherwise, false.
See also:
Decimal.Compare | Decimal.Equals

Return to top


Method: op_LessThan(
   decimal d1,
   decimal d2
)
Summary
Returns a value indicating whether a specified Decimal is less than another specified Decimal.
C# Syntax:
public static bool operator <(
   decimal d1,
   decimal d2
);
Parameters:

d1

A Decimal.

d2

A Decimal.

Return Value:
true if d1 is less than d2; otherwise, false.
See also:
Decimal.Compare

Return to top


Method: op_LessThanOrEqual(
   decimal d1,
   decimal d2
)
Summary
Returns a value indicating whether a specified Decimal is less than or equal to another specified Decimal.
C# Syntax:
public static bool operator <=(
   decimal d1,
   decimal d2
);
Parameters:

d1

A Decimal.

d2

A Decimal.

Return Value:
true if d1 is less than or equal to d2; otherwise, false.
See also:
Decimal.Compare

Return to top


Method: op_Modulus(
   decimal d1,
   decimal d2
)
Summary
Returns the remainder resulting from dividing two specified Decimal values.
C# Syntax:
public static decimal operator %(
   decimal d1,
   decimal d2
);
Parameters:

d1

A Decimal (the dividend).

d2

A Decimal (the divisor).

Return Value:
The Decimal remainder resulting from dividing d1 by d2.
Exceptions
Exception Type Condition
DivideByZeroException d2 is zero.
OverflowException The return value is less than Decimal.MinValue or greater than Decimal.MaxValue.
See also:
Decimal.Remainder

Return to top


Method: op_Multiply(
   decimal d1,
   decimal d2
)
Summary
Multiplies two specified Decimal values.
C# Syntax:
public static decimal operator *(
   decimal d1,
   decimal d2
);
Parameters:

d1

A Decimal.

d2

A Decimal.

Return Value:
The Decimal result of multiplying d1 by d2.
Exceptions
Exception Type Condition
OverflowException The return value is less than Decimal.MinValue or greater than Decimal.MaxValue.
See also:
Decimal.Multiply

Return to top


Method: op_Subtraction(
   decimal d1,
   decimal d2
)
Summary
Subtracts two specified Decimal values.
C# Syntax:
No member name (
   decimal d1,
   decimal d2
);
Parameters:

d1

A Decimal.

d2

A Decimal.

Return Value:
The Decimal result of subtracting d2 from d1.
Exceptions
Exception Type Condition
OverflowException The return value is less than Decimal.MinValue or greater than Decimal.MaxValue.
See also:
Decimal.Subtract

Return to top


Method: op_UnaryNegation(
   decimal d
)
Summary
Negates the value of the specified Decimal operand.
C# Syntax:
public static decimal operator -(
   decimal d
);
Parameters:

d

The Decimal operand.

Return Value:
The result of d multiplied by negative one (-1).
See also:
Decimal.Negate

Return to top


Method: op_UnaryPlus(
   decimal d
)
Summary
Returns the value of the Decimal operand (the sign of the operand is unchanged).
C# Syntax:
public static decimal operator +(
   decimal d
);
Parameters:

d

The Decimal operand.

Return Value:
The value of the operand, d.

Return to top


Overloaded Method: Parse(
   string s
)
Summary
Converts the String representation of a number to its Decimal equivalent.
C# Syntax:
public static decimal Parse(
   string s
);
Parameters:

s

A String containing a number to convert.

Return Value:
The Decimal number equivalent to the number contained in s.
Exceptions
Exception Type Condition
ArgumentNullException s is null.
FormatException s is not of the correct format.
OverflowException s represents a number less than Decimal.MinValue or greater than Decimal.MaxValue.
Remarks
Parameter s contains a number of the form:

[ws][sign]digits[.fractional-digits][ws]

Items in square brackets ('[' and ']') are optional, and other items are as follows.

ws Optional white space. sign An optional sign. digits A sequence of digits ranging from 0 to 9. '.' A culture-specific decimal point symbol. fractional-digits A sequence of digits ranging from 0 to 9.

Parameter s is interpreted using the NumberStyles.Number style.

Parameter s is parsed using the formatting information in a NumberFormatInfo initialized for the current system culture. For more information, see NumberFormatInfo.CurrentInfo.

If necessary, the value of s is rounded using rounding to nearest.

A Decimal has 29 digits of precision. If s represents a number that has more than 29 digits, but has a fractional part and is within the range of Decimal.MaxValue and Decimal.MinValue, the number is rounded, not truncated, to 29 digits using rounding to nearest.

See also:
MSDN: formattingoverview | Decimal.ToString | Math.Round

Return to top


Overloaded Method: Parse(
   string s,
   IFormatProvider provider
)
Summary
Converts the String representation of a number to its Decimal equivalent using the specified culture-specific format information.
C# Syntax:
public static decimal Parse(
   string s,
   IFormatProvider provider
);
Parameters:

s

A String containing a number to convert.

provider

An IFormatProvider that supplies culture-specific formatting information about s.

Return Value:
The Decimal number equivalent to the number contained in s as specified by provider.
Exceptions
Exception Type Condition
ArgumentNullException s is null.
FormatException s is not of the correct format
OverflowException s represents a number less than Decimal.MinValue or greater than Decimal.MaxValue
Remarks
Parameter s contains a number of the form:

[ws][sign]digits[.fractional-digits][ws]

Items in square brackets ('[' and ']') are optional, and other items are as follows.

ws Optional white space. sign An optional sign. digits A sequence of digits ranging from 0 to 9. '.' A culture-specific decimal point symbol. fractional-digits A sequence of digits ranging from 0 to 9.

Parameter s is interpreted using the NumberStyles.Number style.

Parameter provider is an IFormatProvider that obtains a NumberFormatInfo. The NumberFormatInfo provides culture-specific information about the format of s. If provider is null, the NumberFormatInfo for the current culture is used.

A Decimal has 29 digits of precision. If s represents a number that has more than 29 digits, but has a fractional part and is within the range of Decimal.MaxValue and Decimal.MinValue, the number is rounded, not truncated, to 29 digits using rounding to nearest.

See also:
MSDN: formattingoverview | Decimal.ToString | Math.Round

Return to top


Overloaded Method: Parse(
   string s,
   NumberStyles style
)
Summary
Converts the String representation of a number in a specified style to its Decimal equivalent using the specified formatting style.
C# Syntax:
public static decimal Parse(
   string s,
   NumberStyles style
);
Parameters:

s

A String containing a number to convert.

style

The combination of one or more NumberStyles constants that indicate the permitted format of s.

Return Value:
The Decimal number equivalent to the number contained in s as specified by style.
Exceptions
Exception Type Condition
ArgumentNullException s is null.

-or-

style is not a valid combination of bit flags from the NumberStyles enumeration.

FormatException s is not of the correct format.
OverflowException s represents a number less than Decimal.MinValue or greater than Decimal.MaxValue
Remarks
Parameter s contains a number of the form:

[ws][sign]digits[.fractional-digits][ws]

Items in square brackets ('[' and ']') are optional, and other items are as follows.

ws Optional white space. sign An optional sign. digits A sequence of digits ranging from 0 to 9. '.' A culture-specific decimal point symbol. fractional-digits A sequence of digits ranging from 0 to 9.

The style parameter specifies the permitted style of the numeric string. It must be a combination of bit flags from the NumberStyles enumeration. If style is null, s is interpreted using the NumberStyles.Number style.

Parameter s is parsed using the formatting information in a NumberFormatInfo initialized for the current system culture. For more information, see NumberFormatInfo.CurrentInfo.

A Decimal has 29 digits of precision. If s represents a number that has more than 29 digits, but has a fractional part and is within the range of Decimal.MaxValue and Decimal.MinValue, the number is rounded, not truncated, to 29 digits using rounding to nearest.

See also:
MSDN: formattingoverview | Decimal.ToString | Math.Round

Return to top


Overloaded Method: Parse(
   string s,
   NumberStyles style,
   IFormatProvider provider
)
Summary
Converts the String representation of a number to its Decimal equivalent using the specified style and culture-specific format.
C# Syntax:
public static decimal Parse(
   string s,
   NumberStyles style,
   IFormatProvider provider
);
Parameters:

s

A String containing a number to convert.

style

The combination of one or more NumberStyles constants that indicate the permitted format of s.

provider

An IFormatProvider that supplies culture-specific formatting information about s.

Return Value:
The Decimal number equivalent to the number contained in s as specified by style and provider.
Exceptions
Exception Type Condition
ArgumentNullException s is null.

-or-

style is not a valid combination of bit flags from the NumberStyles enumeration

FormatException s is not of the correct format.
OverflowException s represents a number less than Decimal.MinValue or greater than Decimal.MaxValue.
Remarks
Parameter s contains a number of the form:

[ws][sign]digits[.fractional-digits][ws]

Items in square brackets ('[' and ']') are optional, and other items are as follows.

ws Optional white space. sign An optional sign. digits A sequence of digits ranging from 0 to 9. '.' A culture-specific decimal point symbol. fractional-digits A sequence of digits ranging from 0 to 9.

The style parameter can be one or more NumberStyles enumerated constants combined using a bitwise OR operation.

The style parameter specifies the permitted style of the numeric string. It must be a combination of bit flags from the NumberStyles enumeration. If style is null, s is interpreted using the NumberStyles.Number style.

Parameter provider is an IFormatProvider that obtains a NumberFormatInfo. The NumberFormatInfo provides culture-specific information about the format of s. If provider is null, the NumberFormatInfo for the current culture is used.

A Decimal has 29 digits of precision. If s represents a number that has more than 29 digits, but has a fractional part and is within the range of Decimal.MaxValue and Decimal.MinValue, the number is rounded, not truncated, to 29 digits using rounding to nearest.

See also:
MSDN: formattingoverview | Decimal.ToString | Math.Round

Return to top


Method: Remainder(
   decimal d1,
   decimal d2
)
Summary
Computes the remainder after dividing two Decimal values.
C# Syntax:
public static decimal Remainder(
   decimal d1,
   decimal d2
);
Parameters:

d1

A Decimal (the dividend).

d2

A Decimal (the divisor).

Return Value:
The Decimal that is the remainder after dividing d1 by d2.
Exceptions
Exception Type Condition
DivideByZeroException d2 is zero.
OverflowException The return value is less than Decimal.MinValue or greater than Decimal.MaxValue.

Return to top


Method: Round(
   decimal d,
   int decimals
)
Summary
Rounds a Decimal value to a specified number of decimal places.
C# Syntax:
public static decimal Round(
   decimal d,
   int decimals
);
Parameters:

d

A Decimal value to round.

decimals

A value from 0 to 28 that specifies the number of decimal places to round to.

Return Value:
The Decimal number equivalent to d rounded to decimals number of decimal places.
Exceptions
Exception Type Condition
ArgumentOutOfRangeException decimals is not a value from 0 to 28.
Remarks
When d is exactly halfway between two rounded values, the result is the rounded value that has an even digit in the far right decimal position. For example, when rounded to two decimals, the value 2.345 becomes 2.34 and the value 2.355 becomes 2.36. This process is known as rounding toward even, or rounding to nearest.
See also:
Decimal.Floor | Decimal.Truncate

Return to top


Method: Subtract(
   decimal d1,
   decimal d2
)
Summary
Subtracts one specified Decimal value from another.
C# Syntax:
public static decimal Subtract(
   decimal d1,
   decimal d2
);
Parameters:

d1

A Decimal (the minuend).

d2

A Decimal (the subtrahend).

Return Value:
The Decimal result of subtracting d2 from d1.
Exceptions
Exception Type Condition
OverflowException The return value is less than Decimal.MinValue or greater than Decimal.MaxValue.
See also:
Decimal.Add | Decimal.Multiply | Decimal.Divide

Return to top


Method: ToByte(
   decimal value
)
Summary
Converts the value of the specified Decimal to the equivalent 8-bit unsigned integer.
C# Syntax:
public static byte ToByte(
   decimal value
);
Parameters:

value

The Decimal value.

Return Value:
An 8-bit unsigned integer equivalent to value.
Exceptions
Exception Type Condition
OverflowException value is less than Byte.MinValue or greater than Byte.MaxValue.
Remarks
Parameter value is rounded to the nearest integer value toward zero, and that result is returned.
See also:
Byte

Return to top


Method: ToDouble(
   decimal d
)
Summary
Converts the value of the specified Decimal to the equivalent double-precision floating-point number.
C# Syntax:
public static double ToDouble(
   decimal d
);
Parameters:

d

The Decimal value to convert.

Return Value:
A double-precision floating-point number equivalent to d.
Remarks
This operation can produce round-off errors because a double-precision floating-point number has fewer significant digits than a Decimal.
See also:
Double

Return to top


Method: ToInt16(
   decimal value
)
Summary
Converts the value of the specified Decimal to the equivalent 16-bit signed integer.
C# Syntax:
public static short ToInt16(
   decimal value
);
Parameters:

value

A Decimal value.

Return Value:
A 16-bit signed integer equivalent to value.
Exceptions
Exception Type Condition
OverflowException value is less than Int16.MinValue or greater than Int16.MaxValue.
See also:
Int16

Return to top


Method: ToInt32(
   decimal d
)
Summary
Converts the value of the specified Decimal to the equivalent 32-bit signed integer.
C# Syntax:
public static int ToInt32(
   decimal d
);
Parameters:

d

The Decimal value to convert.

Return Value:
A 32-bit signed integer equivalent to the value of d.
Exceptions
Exception Type Condition
OverflowException d is less than Int32.MinValue or greater than Int32.MaxValue.
Remarks
The return value is the integral part of the decimal value; fractional digits are truncated.
See also:
Int32

Return to top


Method: ToInt64(
   decimal d
)
Summary
Converts the value of the specified Decimal to the equivalent 64-bit signed integer.
C# Syntax:
public static long ToInt64(
   decimal d
);
Parameters:

d

The Decimal value to convert.

Return Value:
A 64-bit signed integer equivalent to the value of d.
Exceptions
Exception Type Condition
OverflowException d is less than Int64.MinValue or greater than Int64.MaxValue.
Remarks
The return value is the integral part of the decimal value; fractional digits are truncated.
See also:
Int64

Return to top


Method: ToOACurrency(
   decimal value
)
Summary
Converts the specified Decimal value to the equivalent OLE Automation Currency value, which is contained in a 64-bit signed integer.
C# Syntax:
public static long ToOACurrency(
   decimal value
);
Parameters:

value

A Decimal value.

Return Value:
A 64-bit signed integer that contains the OLE Automation equivalent of value.
See also:
Decimal.FromOACurrency

Return to top


Method: ToSByte(
   decimal value
)
Summary
Converts the value of the specified Decimal to the equivalent 8-bit signed integer.
This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
public static sbyte ToSByte(
   decimal value
);
Parameters:

value

A Decimal value.

Return Value:
An 8-bit signed integer equivalent to value.
Exceptions
Exception Type Condition
OverflowException value is less than SByte.MinValue or greater than SByte.MaxValue.
See also:
SByte

Return to top


Method: ToSingle(
   decimal d
)
Summary
Converts the value of the specified Decimal to the equivalent single-precision floating-point number.
C# Syntax:
public static float ToSingle(
   decimal d
);
Parameters:

d

A Decimal value to convert.

Return Value:
A single-precision floating-point number equivalent to the value of d.
Remarks
This operation can produce round-off errors because a single-precision floating-point number has fewer significant digits than a Decimal.
See also:
Single

Return to top


Overloaded Method: ToString()
Summary
Converts the numeric value of this instance to its equivalent String representation.
C# Syntax:
public override string ToString();
Return Value:
A String representing the value of this instance.
Remarks
The return value is formatted with the general format specifier ("G"), and the NumberFormatInfo for the current culture.
See also:
MSDN: formattingoverview | Decimal.Parse

Return to top


Overloaded Method: ToString(
   IFormatProvider provider
)
Summary
Converts the numeric value of this instance to its equivalent String representation using the specified culture-specific format information.
C# Syntax:
public string ToString(
   IFormatProvider provider
);
Parameters:

provider

An IFormatProvider that supplies culture-specific formatting information.

Return Value:
The String representation of the value of this instance as specified by provider.
Remarks
Parameter provider is an IFormatProvider that obtains a NumberFormatInfo. The NumberFormatInfo provides culture-specific format information about this instance. If provider is null, the return value for this instance is formatted with the NumberFormatInfo for the current culture.
See also:
MSDN: formattingoverview | Decimal.Parse

Return to top


Overloaded Method: ToString(
   string format
)
Summary
Converts the numeric value of this instance to its equivalent String representation, using the specified format.
C# Syntax:
public string ToString(
   string format
);
Parameters:

format

A String containing a format specification.

Return Value:
A String representation of the value of this instance as specified by format.
Exceptions
Exception Type Condition
FormatException format is invalid.
Remarks
If format is null or an empty string, the return value of this instance is formatted with the general format specifier ("G").

The return value is formatted with the NumberFormatInfo for the current culture.

See also:
MSDN: formattingoverview | Decimal.Parse

Return to top


Overloaded Method: ToString(
   string format,
   IFormatProvider provider
)
Summary
Converts the numeric value of this instance to its equivalent String representation using the specified format and culture-specific format information.
C# Syntax:
public string ToString(
   string format,
   IFormatProvider provider
);
Parameters:

format

A format specification.

provider

An IFormatProvider that supplies culture-specific formatting information.

Return Value:
The String representation of the value of this instance as specified by format and provider.
Exceptions
Exception Type Condition
FormatException format is invalid.
Remarks
If format is null or an empty string, the return value for this instance is formatted with the general format specifier ("G").

Parameter provider is an IFormatProvider that obtains a NumberFormatInfo. The NumberFormatInfo provides culture-specific format information about this instance. If provider is null, the return value for this instance is formatted with the NumberFormatInfo for the current culture.

See also:
MSDN: formattingoverview | Decimal.Parse

Return to top


Method: ToUInt16(
   decimal value
)
Summary
Converts the value of the specified Decimal to the equivalent 16-bit unsigned integer.
This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
public static ushort ToUInt16(
   decimal value
);
Parameters:

value

A Decimal value to convert.

Return Value:
A 16-bit unsigned integer equivalent to the value of value.
Exceptions
Exception Type Condition
OverflowException value is greater than UInt16.MaxValue or less than UInt16.MinValue.
Remarks
The return value is the integral part of the decimal value; fractional digits are truncated.
See also:
UInt16

Return to top


Method: ToUInt32(
   decimal d
)
Summary
Converts the value of the specified Decimal to the equivalent 32-bit unsigned integer.
This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
public static uint ToUInt32(
   decimal d
);
Parameters:

d

A Decimal value to convert.

Return Value:
A 32-bit unsigned integer equivalent to the value of d.
Exceptions
Exception Type Condition
OverflowException d is negative or greater than UInt32.MaxValue.
Remarks
The return value is the integral part of the decimal value; fractional digits are truncated.
See also:
UInt32

Return to top


Method: ToUInt64(
   decimal d
)
Summary
Converts the value of the specified Decimal to the equivalent 64-bit unsigned integer.
This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
public static ulong ToUInt64(
   decimal d
);
Parameters:

d

A Decimal value to convert.

Return Value:
A 64-bit unsigned integer equivalent to the value of d.
Exceptions
Exception Type Condition
OverflowException d is negative or greater than UInt64.MaxValue.
Remarks
The return value is the integral part of the decimal value; fractional digits are truncated.
See also:
UInt64

Return to top


Method: Truncate(
   decimal d
)
Summary
Returns the integral digits of the specified Decimal; any fractional digits are discarded.
C# Syntax:
public static decimal Truncate(
   decimal d
);
Parameters:

d

A Decimal to truncate.

Return Value:
The Decimal result of d rounded toward zero, to the nearest whole number.
Remarks
This method rounds d toward zero, to the nearest whole number, which corresponds to discarding any digits after the decimal point.
See also:
Decimal.Round | Decimal.Floor

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.