Decimal Structure
TOC
Collapse the table of content
Expand the table of content

Decimal Structure

 

Represents a decimal number.

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

[SerializableAttribute]
[ComVisibleAttribute(true)]
public struct Decimal : IFormattable, IComparable, IConvertible, 
	IDeserializationCallback, IComparable<decimal>, IEquatable<decimal>

NameDescription
System_CAPS_pubmethodDecimal(Double)

Initializes a new instance of Decimal to the value of the specified double-precision floating-point number.

System_CAPS_pubmethodDecimal(Int32)

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

System_CAPS_pubmethodDecimal(Int32, Int32, Int32, Boolean, Byte)

Initializes a new instance of Decimal from parameters specifying the instance's constituent parts.

System_CAPS_pubmethodDecimal(Int32[])

Initializes a new instance of Decimal to a decimal value represented in binary and contained in a specified array.

System_CAPS_pubmethodDecimal(Int64)

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

System_CAPS_pubmethodDecimal(Single)

Initializes a new instance of Decimal to the value of the specified single-precision floating-point number.

System_CAPS_pubmethodDecimal(UInt32)

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

System_CAPS_pubmethodDecimal(UInt64)

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

NameDescription
System_CAPS_pubmethodSystem_CAPS_staticAdd(Decimal, Decimal)

Adds two specified Decimal values.

System_CAPS_pubmethodSystem_CAPS_staticCeiling(Decimal)

Returns the smallest integral value that is greater than or equal to the specified decimal number.

System_CAPS_pubmethodSystem_CAPS_staticCompare(Decimal, Decimal)

Compares two specified Decimal values.

System_CAPS_pubmethodCompareTo(Decimal)

Compares this instance to a specified Decimal object and returns a comparison of their relative values.

System_CAPS_pubmethodCompareTo(Object)

Compares this instance to a specified object and returns a comparison of their relative values.

System_CAPS_pubmethodSystem_CAPS_staticDivide(Decimal, Decimal)

Divides two specified Decimal values.

System_CAPS_pubmethodEquals(Decimal)

Returns a value indicating whether this instance and a specified Decimal object represent the same value.

System_CAPS_pubmethodSystem_CAPS_staticEquals(Decimal, Decimal)

Returns a value indicating whether two specified instances of Decimal represent the same value.

System_CAPS_pubmethodEquals(Object)

Returns a value indicating whether this instance and a specified Object represent the same type and value.(Overrides ValueType.Equals(Object).)

System_CAPS_pubmethodSystem_CAPS_staticFloor(Decimal)

Rounds a specified Decimal number to the closest integer toward negative infinity.

System_CAPS_pubmethodSystem_CAPS_staticFromOACurrency(Int64)

Converts the specified 64-bit signed integer, which contains an OLE Automation Currency value, to the equivalent Decimal value.

System_CAPS_pubmethodSystem_CAPS_staticGetBits(Decimal)

Converts the value of a specified instance of Decimal to its equivalent binary representation.

System_CAPS_pubmethodGetHashCode()

Returns the hash code for this instance.(Overrides ValueType.GetHashCode().)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodGetTypeCode()

Returns the TypeCode for value type Decimal.

System_CAPS_pubmethodSystem_CAPS_staticMultiply(Decimal, Decimal)

Multiplies two specified Decimal values.

System_CAPS_pubmethodSystem_CAPS_staticNegate(Decimal)

Returns the result of multiplying the specified Decimal value by negative one.

System_CAPS_pubmethodSystem_CAPS_staticParse(String)

Converts the string representation of a number to its Decimal equivalent.

System_CAPS_pubmethodSystem_CAPS_staticParse(String, IFormatProvider)

Converts the string representation of a number to its Decimal equivalent using the specified culture-specific format information.

System_CAPS_pubmethodSystem_CAPS_staticParse(String, NumberStyles)

Converts the string representation of a number in a specified style to its Decimal equivalent.

System_CAPS_pubmethodSystem_CAPS_staticParse(String, NumberStyles, IFormatProvider)

Converts the string representation of a number to its Decimal equivalent using the specified style and culture-specific format.

System_CAPS_pubmethodSystem_CAPS_staticRemainder(Decimal, Decimal)

Computes the remainder after dividing two Decimal values.

System_CAPS_pubmethodSystem_CAPS_staticRound(Decimal)

Rounds a decimal value to the nearest integer.

System_CAPS_pubmethodSystem_CAPS_staticRound(Decimal, Int32)

Rounds a Decimal value to a specified number of decimal places.

System_CAPS_pubmethodSystem_CAPS_staticRound(Decimal, Int32, MidpointRounding)

Rounds a decimal value to a specified precision. A parameter specifies how to round the value if it is midway between two other numbers.

System_CAPS_pubmethodSystem_CAPS_staticRound(Decimal, MidpointRounding)

Rounds a decimal value to the nearest integer. A parameter specifies how to round the value if it is midway between two other numbers.

System_CAPS_pubmethodSystem_CAPS_staticSubtract(Decimal, Decimal)

Subtracts one specified Decimal value from another.

System_CAPS_pubmethodSystem_CAPS_staticToByte(Decimal)

Converts the value of the specified Decimal to the equivalent 8-bit unsigned integer.

System_CAPS_pubmethodSystem_CAPS_staticToDouble(Decimal)

Converts the value of the specified Decimal to the equivalent double-precision floating-point number.

System_CAPS_pubmethodSystem_CAPS_staticToInt16(Decimal)

Converts the value of the specified Decimal to the equivalent 16-bit signed integer.

System_CAPS_pubmethodSystem_CAPS_staticToInt32(Decimal)

Converts the value of the specified Decimal to the equivalent 32-bit signed integer.

System_CAPS_pubmethodSystem_CAPS_staticToInt64(Decimal)

Converts the value of the specified Decimal to the equivalent 64-bit signed integer.

System_CAPS_pubmethodSystem_CAPS_staticToOACurrency(Decimal)

Converts the specified Decimal value to the equivalent OLE Automation Currency value, which is contained in a 64-bit signed integer.

System_CAPS_pubmethodSystem_CAPS_staticToSByte(Decimal)

Converts the value of the specified Decimal to the equivalent 8-bit signed integer.

System_CAPS_pubmethodSystem_CAPS_staticToSingle(Decimal)

Converts the value of the specified Decimal to the equivalent single-precision floating-point number.

System_CAPS_pubmethodToString()

Converts the numeric value of this instance to its equivalent string representation.(Overrides ValueType.ToString().)

System_CAPS_pubmethodToString(IFormatProvider)

Converts the numeric value of this instance to its equivalent string representation using the specified culture-specific format information.

System_CAPS_pubmethodToString(String)

Converts the numeric value of this instance to its equivalent string representation, using the specified format.

System_CAPS_pubmethodToString(String, IFormatProvider)

Converts the numeric value of this instance to its equivalent string representation using the specified format and culture-specific format information.

System_CAPS_pubmethodSystem_CAPS_staticToUInt16(Decimal)

Converts the value of the specified Decimal to the equivalent 16-bit unsigned integer.

System_CAPS_pubmethodSystem_CAPS_staticToUInt32(Decimal)

Converts the value of the specified Decimal to the equivalent 32-bit unsigned integer.

System_CAPS_pubmethodSystem_CAPS_staticToUInt64(Decimal)

Converts the value of the specified Decimal to the equivalent 64-bit unsigned integer.

System_CAPS_pubmethodSystem_CAPS_staticTruncate(Decimal)

Returns the integral digits of the specified Decimal; any fractional digits are discarded.

System_CAPS_pubmethodSystem_CAPS_staticTryParse(String, Decimal)

Converts the string representation of a number to its Decimal equivalent. A return value indicates whether the conversion succeeded or failed.

System_CAPS_pubmethodSystem_CAPS_staticTryParse(String, NumberStyles, IFormatProvider, Decimal)

Converts the string representation of a number to its Decimal equivalent using the specified style and culture-specific format. A return value indicates whether the conversion succeeded or failed.

NameDescription
System_CAPS_pubfieldSystem_CAPS_staticMaxValue

Represents the largest possible value of Decimal. This field is constant and read-only.

System_CAPS_pubfieldSystem_CAPS_staticMinusOne

Represents the number negative one (-1).

System_CAPS_pubfieldSystem_CAPS_staticMinValue

Represents the smallest possible value of Decimal. This field is constant and read-only.

System_CAPS_pubfieldSystem_CAPS_staticOne

Represents the number one (1).

System_CAPS_pubfieldSystem_CAPS_staticZero

Represents the number zero (0).

NameDescription
System_CAPS_puboperatorSystem_CAPS_staticAddition(Decimal, Decimal)

Adds two specified Decimal values.

System_CAPS_puboperatorSystem_CAPS_staticDecrement(Decimal)

Decrements the Decimal operand by one.

System_CAPS_puboperatorSystem_CAPS_staticDivision(Decimal, Decimal)

Divides two specified Decimal values.

System_CAPS_puboperatorSystem_CAPS_staticEquality(Decimal, Decimal)

Returns a value that indicates whether two Decimal values are equal.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(Decimal to Byte)

Defines an explicit conversion of a Decimal to an 8-bit unsigned integer.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(Decimal to Char)

Defines an explicit conversion of a Decimal to a Unicode character.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(Decimal to Double)

Defines an explicit conversion of a Decimal to a double-precision floating-point number.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(Decimal to Int16)

Defines an explicit conversion of a Decimal to a 16-bit signed integer.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(Decimal to Int32)

Defines an explicit conversion of a Decimal to a 32-bit signed integer.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(Decimal to Int64)

Defines an explicit conversion of a Decimal to a 64-bit signed integer.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(Decimal to SByte)

Defines an explicit conversion of a Decimal to an 8-bit signed integer.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(Decimal to Single)

Defines an explicit conversion of a Decimal to a single-precision floating-point number.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(Decimal to UInt16)

Defines an explicit conversion of a Decimal to a 16-bit unsigned integer.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(Decimal to UInt32)

Defines an explicit conversion of a Decimal to a 32-bit unsigned integer.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(Decimal to UInt64)

Defines an explicit conversion of a Decimal to a 64-bit unsigned integer.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(Double to Decimal)

Defines an explicit conversion of a double-precision floating-point number to a Decimal.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(Single to Decimal)

Defines an explicit conversion of a single-precision floating-point number to a Decimal.

System_CAPS_puboperatorSystem_CAPS_staticGreaterThan(Decimal, Decimal)

Returns a value indicating whether a specified Decimal is greater than another specified Decimal.

System_CAPS_puboperatorSystem_CAPS_staticGreaterThanOrEqual(Decimal, Decimal)

Returns a value indicating whether a specified Decimal is greater than or equal to another specified Decimal.

System_CAPS_puboperatorSystem_CAPS_staticImplicit(Byte to Decimal)

Defines an implicit conversion of an 8-bit unsigned integer to a Decimal.

System_CAPS_puboperatorSystem_CAPS_staticImplicit(Char to Decimal)

Defines an implicit conversion of a Unicode character to a Decimal.

System_CAPS_puboperatorSystem_CAPS_staticImplicit(Int16 to Decimal)

Defines an implicit conversion of a 16-bit signed integer to a Decimal.

System_CAPS_puboperatorSystem_CAPS_staticImplicit(Int32 to Decimal)

Defines an implicit conversion of a 32-bit signed integer to a Decimal.

System_CAPS_puboperatorSystem_CAPS_staticImplicit(Int64 to Decimal)

Defines an implicit conversion of a 64-bit signed integer to a Decimal.

System_CAPS_puboperatorSystem_CAPS_staticImplicit(SByte to Decimal)

Defines an implicit conversion of an 8-bit signed integer to a Decimal.

System_CAPS_puboperatorSystem_CAPS_staticImplicit(UInt16 to Decimal)

Defines an implicit conversion of a 16-bit unsigned integer to a Decimal.

System_CAPS_puboperatorSystem_CAPS_staticImplicit(UInt32 to Decimal)

Defines an implicit conversion of a 32-bit unsigned integer to a Decimal.

System_CAPS_puboperatorSystem_CAPS_staticImplicit(UInt64 to Decimal)

Defines an implicit conversion of a 64-bit unsigned integer to a Decimal.

System_CAPS_puboperatorSystem_CAPS_staticIncrement(Decimal)

Increments the Decimal operand by 1.

System_CAPS_puboperatorSystem_CAPS_staticInequality(Decimal, Decimal)

Returns a value that indicates whether two Decimal objects have different values.

System_CAPS_puboperatorSystem_CAPS_staticLessThan(Decimal, Decimal)

Returns a value indicating whether a specified Decimal is less than another specified Decimal.

System_CAPS_puboperatorSystem_CAPS_staticLessThanOrEqual(Decimal, Decimal)

Returns a value indicating whether a specified Decimal is less than or equal to another specified Decimal.

System_CAPS_puboperatorSystem_CAPS_staticModulus(Decimal, Decimal)

Returns the remainder resulting from dividing two specified Decimal values.

System_CAPS_puboperatorSystem_CAPS_staticMultiply(Decimal, Decimal)

Multiplies two specified Decimal values.

System_CAPS_puboperatorSystem_CAPS_staticSubtraction(Decimal, Decimal)

Subtracts two specified Decimal values.

System_CAPS_puboperatorSystem_CAPS_staticUnaryNegation(Decimal)

Negates the value of the specified Decimal operand.

System_CAPS_puboperatorSystem_CAPS_staticUnaryPlus(Decimal)

Returns the value of the Decimal operand (the sign of the operand is unchanged).

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privmethodIConvertible.ToBoolean(IFormatProvider)

This API supports the product infrastructure and is not intended to be used directly from your code. For a description of this member, see IConvertible.ToBoolean.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIConvertible.ToByte(IFormatProvider)

This API supports the product infrastructure and is not intended to be used directly from your code. For a description of this member, see IConvertible.ToByte.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIConvertible.ToChar(IFormatProvider)

This API supports the product infrastructure and is not intended to be used directly from your code. This conversion is not supported. Attempting to use this method throws an InvalidCastException.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIConvertible.ToDateTime(IFormatProvider)

This API supports the product infrastructure and is not intended to be used directly from your code. This conversion is not supported. Attempting to use this method throws an InvalidCastException.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIConvertible.ToDecimal(IFormatProvider)

This API supports the product infrastructure and is not intended to be used directly from your code. For a description of this member, see IConvertible.ToDecimal.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIConvertible.ToDouble(IFormatProvider)

This API supports the product infrastructure and is not intended to be used directly from your code. For a description of this member, see IConvertible.ToDouble.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIConvertible.ToInt16(IFormatProvider)

This API supports the product infrastructure and is not intended to be used directly from your code. For a description of this member, see IConvertible.ToInt16.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIConvertible.ToInt32(IFormatProvider)

This API supports the product infrastructure and is not intended to be used directly from your code. For a description of this member, see IConvertible.ToInt32.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIConvertible.ToInt64(IFormatProvider)

This API supports the product infrastructure and is not intended to be used directly from your code. For a description of this member, see IConvertible.ToInt64.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIConvertible.ToSByte(IFormatProvider)

This API supports the product infrastructure and is not intended to be used directly from your code. For a description of this member, see IConvertible.ToSByte.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIConvertible.ToSingle(IFormatProvider)

This API supports the product infrastructure and is not intended to be used directly from your code. For a description of this member, see IConvertible.ToSingle.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIConvertible.ToType(Type, IFormatProvider)

This API supports the product infrastructure and is not intended to be used directly from your code. For a description of this member, see IConvertible.ToType.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIConvertible.ToUInt16(IFormatProvider)

This API supports the product infrastructure and is not intended to be used directly from your code. For a description of this member, see IConvertible.ToUInt16.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIConvertible.ToUInt32(IFormatProvider)

This API supports the product infrastructure and is not intended to be used directly from your code. For a description of this member, see IConvertible.ToInt32.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIConvertible.ToUInt64(IFormatProvider)

This API supports the product infrastructure and is not intended to be used directly from your code. For a description of this member, see IConvertible.ToInt64.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIDeserializationCallback.OnDeserialization(Object)

This API supports the product infrastructure and is not intended to be used directly from your code. Runs when the deserialization of an object has been completed.

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 that require large numbers of significant integral and fractional digits and no round-off errors. The Decimal type does not eliminate the need for rounding. Rather, it minimizes errors due to rounding. For example, the following code produces a result of 0.9999999999999999999999999999 instead of 1.

decimal dividend = Decimal.One;
decimal divisor = 3;
// The following displays 0.9999999999999999999999999999 to the console
Console.WriteLine(dividend/divisor * divisor);   

When the result of the division and multiplication is passed to the Round method, the result suffers no loss of precision, as the following code shows.

decimal dividend = Decimal.One;
decimal divisor = 3;
// The following displays 1.00 to the console
Console.WriteLine(Math.Round(dividend/divisor * divisor, 2));   

A decimal number is a floating-point value that consists of a sign, a numeric value where each digit in the value ranges from 0 to 9, and a scaling factor that indicates the position of a floating decimal point that separates the integral and fractional parts of the numeric value.

The binary representation of a Decimal value 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 the form, ((-296 to 296) / 10(0 to 28)), where -(296-1) is equal to MinValue, and 296-1 is equal to MaxValue. For more information about the binary representation of Decimal values and an example, see the Decimal(Int32[]) constructor and the GetBits method.

The scaling factor also preserves any trailing zeros in a Decimal number. Trailing zeros do not affect the value of a Decimal number in arithmetic or comparison operations. However, trailing zeros might be revealed by the ToString method if an appropriate format string is applied.

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

Conversions from Decimal to any of the integral types are narrowing conversions that round the Decimal value to the nearest integer value toward zero. Some languages, such as C#, also support the conversion of Decimal values to Char values. If the result of these conversions cannot be represented in the destination type, an OverflowException exception is thrown.

The Decimal type also provides methods that convert Decimal values to and from Single and Double values. 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 does not throw an exception.

Conversions from Single or Double to Decimal throw an OverflowException exception if the result of the conversion cannot be represented as a Decimal.

The Decimal type supports standard mathematical operations such as addition, subtraction, division, multiplication, and unary negation. You can also work directly with the binary representation of a Decimal value by calling the GetBits method.

To compare two Decimal values, you can use the standard numeric comparison operators, or you can call the CompareTo or Equals method.

You can also call the members of the Math class to perform a wide range of numeric operations, including getting the absolute value of a number, determining the maximum or minimum value of two Decimal values, getting the sign of a number, and rounding a number.

The following code example demonstrates the use of Decimal.

/// <summary>
/// Keeping my fortune in Decimals to avoid the round-off errors.
/// </summary>
class PiggyBank {
	protected decimal MyFortune;

	public void AddPenny() {
		MyFortune = Decimal.Add(MyFortune, .01m);
	}

	public decimal Capacity {
		get {
			return Decimal.MaxValue;
		}
	}

	public decimal Dollars {
		get {
			return Decimal.Floor(MyFortune);
		}
	}

	public decimal Cents {
		get {
			return Decimal.Subtract(MyFortune, Decimal.Floor(MyFortune));
		}
	}

	public override string ToString() {
		return MyFortune.ToString("C")+" in piggy bank";
	}
}

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1

All members of this type are thread safe. Members that appear to modify instance state actually return a new instance initialized with the new value. As with any other type, reading and writing to a shared variable that contains an instance of this type must be protected by a lock to guarantee thread safety.

System_CAPS_cautionCaution

Assigning an instance of this type is not thread safe on all hardware platforms because the binary representation of that instance might be too large to assign in a single atomic operation.

Return to top
Show:
© 2016 Microsoft