[Serializable] |
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.
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. |
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). |
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. |
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). |
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:
public Decimal( |
value
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. |
public Decimal( |
value
public Decimal( |
bits
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. |
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.
public Decimal( |
value
public Decimal( |
value
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. |
[CLSCompliant(false)] |
value
[CLSCompliant(false)] |
value
lo
mid
hi
isNegative
scale
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | scale is greater than 28. |
public static readonly decimal MaxValue;
|
public static readonly decimal MinusOne;
|
public static readonly decimal MinValue;
|
public static readonly decimal One;
|
public static readonly decimal Zero;
|
d1
d2
Exception Type | Condition |
---|---|
OverflowException | The sum of d1 and d2 is less than Decimal.MinValue or greater than Decimal.MaxValue. |
d1
d2
Return Value | Meaning |
---|---|
Less than zero | is less than . |
Zero | and are equal. |
Greater than zero | is greater than . |
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. |
Exception Type | Condition |
---|---|
ArgumentException | value is not a Decimal or null. |
Parameter value must be null or an instance of Decimal; otherwise, an exception is thrown.
d1
d2
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. |
value
d1
d2
~Decimal(); |
d
-or-
If d doesn't have a fractional part, d is returned unchanged.
cy
d
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.
public override int GetHashCode(); |
public Type GetType(); |
public TypeCode GetTypeCode(); |
protected object MemberwiseClone(); |
d1
d2
Exception Type | Condition |
---|---|
OverflowException | The return value is less than Decimal.MinValue or greater than Decimal.MaxValue. |
d
-or-
Zero, if d is zero.
d1
d2
Exception Type | Condition |
---|---|
OverflowException | The return value is less than Decimal.MinValue or greater than Decimal.MaxValue. |
public static decimal operator --( |
d
Exception Type | Condition |
---|---|
OverflowException | The return value is less than Decimal.MinValue or greater than Decimal.MaxValue. |
d1
d2
Exception Type | Condition |
---|---|
DivideByZeroException | d2 is zero. |
OverflowException | The return value is less than Decimal.MinValue or greater than Decimal.MaxValue. |
d1
d2
value
Exception Type | Condition |
---|---|
OverflowException | value is less than Int16.MinValue or greater than Int16.MaxValue. |
value
Exception Type | Condition |
---|---|
OverflowException | value is less than Int64.MinValue or greater than Int64.MaxValue. |
value
Exception Type | Condition |
---|---|
OverflowException | value is negative or greater than UInt32.MaxValue. |
value
Exception Type | Condition |
---|---|
OverflowException | value is less than Int32.MinValue or greater than Int32.MaxValue. |
value
Exception Type | Condition |
---|---|
OverflowException | value is greater than UInt16.MaxValue or less than UInt16.MinValue. |
value
Exception Type | Condition |
---|---|
OverflowException | value is less than Int16.MinValue or greater than Int16.MaxValue. |
value
Exception Type | Condition |
---|---|
OverflowException | value is less than SByte.MinValue or greater than SByte.MaxValue. |
value
value
value
Exception Type | Condition |
---|---|
OverflowException | value is negative or greater than UInt64.MaxValue. |
value
Exception Type | Condition |
---|---|
OverflowException | value is less than Byte.MinValue or greater than Byte.MaxValue. |
value
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. |
value
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. |
d1
d2
d1
d2
value
value
value
value
value
value
value
value
value
public static decimal operator ++( |
d
Exception Type | Condition |
---|---|
OverflowException | The return value is less than Decimal.MinValue or greater than Decimal.MaxValue. |
d1
d2
d1
d2
d1
d2
d1
d2
Exception Type | Condition |
---|---|
DivideByZeroException | d2 is zero. |
OverflowException | The return value is less than Decimal.MinValue or greater than Decimal.MaxValue. |
d1
d2
Exception Type | Condition |
---|---|
OverflowException | The return value is less than Decimal.MinValue or greater than Decimal.MaxValue. |
d1
d2
Exception Type | Condition |
---|---|
OverflowException | The return value is less than Decimal.MinValue or greater than Decimal.MaxValue. |
public static decimal operator -( |
d
public static decimal operator +( |
d
s
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. |
[ws][sign]digits[.fractional-digits][ws]
Items in square brackets ('[' and ']') are optional, and other items are as follows.
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.
public static decimal Parse( |
s
provider
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 |
[ws][sign]digits[.fractional-digits][ws]
Items in square brackets ('[' and ']') are optional, and other items are as follows.
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.
public static decimal Parse( |
s
style
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 |
[ws][sign]digits[.fractional-digits][ws]
Items in square brackets ('[' and ']') are optional, and other items are as follows.
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.
public static decimal Parse( |
s
style
provider
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. |
[ws][sign]digits[.fractional-digits][ws]
Items in square brackets ('[' and ']') are optional, and other items are as follows.
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.
d1
d2
Exception Type | Condition |
---|---|
DivideByZeroException | d2 is zero. |
OverflowException | The return value is less than Decimal.MinValue or greater than Decimal.MaxValue. |
d
decimals
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | decimals is not a value from 0 to 28. |
d1
d2
Exception Type | Condition |
---|---|
OverflowException | The return value is less than Decimal.MinValue or greater than Decimal.MaxValue. |
value
Exception Type | Condition |
---|---|
OverflowException | value is less than Byte.MinValue or greater than Byte.MaxValue. |
d
value
Exception Type | Condition |
---|---|
OverflowException | value is less than Int16.MinValue or greater than Int16.MaxValue. |
d
Exception Type | Condition |
---|---|
OverflowException | d is less than Int32.MinValue or greater than Int32.MaxValue. |
d
Exception Type | Condition |
---|---|
OverflowException | d is less than Int64.MinValue or greater than Int64.MaxValue. |
value
value
Exception Type | Condition |
---|---|
OverflowException | value is less than SByte.MinValue or greater than SByte.MaxValue. |
d
public override string ToString(); |
public string ToString( |
provider
format
Exception Type | Condition |
---|---|
FormatException | format is invalid. |
The return value is formatted with the NumberFormatInfo for the current culture.
public string ToString( |
format
provider
Exception Type | Condition |
---|---|
FormatException | format is invalid. |
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.
value
Exception Type | Condition |
---|---|
OverflowException | value is greater than UInt16.MaxValue or less than UInt16.MinValue. |
d
Exception Type | Condition |
---|---|
OverflowException | d is negative or greater than UInt32.MaxValue. |
d
Exception Type | Condition |
---|---|
OverflowException | d is negative or greater than UInt64.MaxValue. |
d