Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Decimal Structure

Represents a decimal number.

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

'Declaration
<ComVisibleAttribute(True)> _
Public Structure Decimal _
	Implements IFormattable, IComparable, IConvertible, IComparable(Of Decimal),  _
	IEquatable(Of Decimal)

The Decimal type exposes the following members.

  NameDescription
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360Decimal(Double)Initializes a new instance of Decimal to the value of the specified double-precision floating-point number.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360Decimal(Int32)Initializes a new instance of Decimal to the value of the specified 32-bit signed integer.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360Decimal(Int32())Initializes a new instance of Decimal to a decimal value represented in binary and contained in a specified array.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360Decimal(Int64)Initializes a new instance of Decimal to the value of the specified 64-bit signed integer.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360Decimal(Single)Initializes a new instance of Decimal to the value of the specified single-precision floating-point number.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360Decimal(UInt32)Initializes a new instance of Decimal to the value of the specified 32-bit unsigned integer.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360Decimal(UInt64)Initializes a new instance of Decimal to the value of the specified 64-bit unsigned integer.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360Decimal(Int32, Int32, Int32, Boolean, Byte)Initializes a new instance of Decimal from parameters specifying the instance's constituent parts.
Top

  NameDescription
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360AddAdds two specified Decimal values.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360CeilingReturns the smallest integral value greater than or equal to the specified decimal number.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360CompareCompares two specified Decimal values and returns an integer that indicates whether the first value is greater than, less than, or equal to the second value.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360CompareTo(Decimal)Compares this instance to a specified Decimal object and returns an integer that indicates whether the value of this instance is greater than, less than, or equal to the value of the specified Decimal.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360CompareTo(Object)Compares this instance to a specified Object and returns an integer that indicates whether the value of this instance is greater than, less than, or equal to the value of the specified Object.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360DivideDivides two specified Decimal values.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360Equals(Decimal)Returns a value indicating whether this instance and a specified Decimal object represent the same value.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360Equals(Object)Returns a value indicating whether this instance and a specified Object represent the same type and value. (Overrides ValueType.Equals(Object).)
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360Equals(Decimal, Decimal)Returns a value indicating whether two specified instances of Decimal represent the same value.
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360FinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360FloorRounds a specified Decimal number to the closest integer toward negative infinity.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360GetBitsConverts the value of a specified instance of Decimal to its equivalent binary representation.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetHashCodeReturns the hash code for this instance. (Overrides ValueType.GetHashCode.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetTypeCodeReturns the TypeCode for value type Decimal.
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360MemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360MultiplyMultiplies two specified Decimal values.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360NegateReturns the result of multiplying the specified Decimal value by negative one.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360Parse(String)Converts the string representation of a number to its Decimal equivalent.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360Parse(String, NumberStyles)Converts the string representation of a number in a specified style to its Decimal equivalent.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360Parse(String, IFormatProvider)Converts the string representation of a number to its Decimal equivalent using the specified culture-specific format information.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360Parse(String, NumberStyles, IFormatProvider)Converts the string representation of a number to its Decimal equivalent using the specified style and culture-specific format.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360RemainderComputes the remainder after dividing two Decimal values.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360RoundRounds a Decimal value to a specified number of decimal places.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360SubtractSubtracts one specified Decimal value from another.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360ToByteConverts the value of the specified Decimal to the equivalent 8-bit unsigned integer.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360ToDoubleConverts the value of the specified Decimal to the equivalent double-precision floating-point number.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360ToInt16Converts the value of the specified Decimal to the equivalent 16-bit signed integer.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360ToInt32Converts the value of the specified Decimal to the equivalent 32-bit signed integer.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360ToInt64Converts the value of the specified Decimal to the equivalent 64-bit signed integer.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360ToSByteConverts the value of the specified Decimal to the equivalent 8-bit signed integer.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360ToSingleConverts the value of the specified Decimal to the equivalent single-precision floating-point number.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360ToStringConverts the numeric value of this instance to its equivalent string representation. (Overrides ValueType.ToString.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360ToString(IFormatProvider)Converts the numeric value of this instance to its equivalent string representation using the specified culture-specific format information.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360ToString(String)Converts the numeric value of this instance to its equivalent string representation, using the specified format.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360ToString(String, IFormatProvider)Converts the numeric value of this instance to its equivalent string representation using the specified format and culture-specific format information.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360ToUInt16Converts the value of the specified Decimal to the equivalent 16-bit unsigned integer.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360ToUInt32Converts the value of the specified Decimal to the equivalent 32-bit unsigned integer.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360ToUInt64Converts the value of the specified Decimal to the equivalent 64-bit unsigned integer.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360TruncateReturns the integral digits of the specified Decimal; any fractional digits are discarded.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360TryParse(String, Decimal)Converts the string representation of a number to its Decimal equivalent. A return value indicates whether the conversion succeeded or failed.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360TryParse(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.
Top

  NameDescription
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360AdditionAdds two specified Decimal values.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360DecrementDecrements the Decimal operand by one.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360DivisionDivides two specified Decimal values.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360EqualityReturns a value indicating whether two instances of Decimal are equal.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360Narrowing(Decimal to UInt16)Converts a Decimal to a 16-bit unsigned integer.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360Narrowing(Decimal to SByte)Converts a Decimal to an 8-bit signed integer.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360Narrowing(Decimal to UInt32)Converts a Decimal to a 32-bit unsigned integer.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360Narrowing(Decimal to Char)Converts a Decimal to a Unicode character.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360Narrowing(Decimal to Byte)Converts a Decimal to an 8-bit unsigned integer.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360Narrowing(Decimal to Int64)Converts a Decimal to a 64-bit signed integer.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360Narrowing(Decimal to Double)Converts a Decimal to a double-precision floating-point number.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360Narrowing(Decimal to Int16)Converts a Decimal to a 16-bit signed integer.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360Narrowing(Decimal to UInt64)Converts a Decimal to a 64-bit unsigned integer.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360Narrowing(Decimal to Single)Converts a Decimal to a single-precision floating-point number.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360Narrowing(Decimal to Int32)Converts a Decimal to a 32-bit signed integer.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360Narrowing(Double to Decimal)Converts a double-precision floating-point number to a Decimal.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360Narrowing(Single to Decimal)Converts a single-precision floating-point number to a Decimal.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360GreaterThanReturns a value indicating whether a specified Decimal is greater than another specified Decimal.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360GreaterThanOrEqualReturns a value indicating whether a specified Decimal is greater than or equal to another specified Decimal.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360Widening(Byte to Decimal)Converts an 8-bit unsigned integer to a Decimal.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360Widening(Char to Decimal)Converts a Unicode character to a Decimal.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360Widening(Int16 to Decimal)Converts a 16-bit signed integer to a Decimal.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360Widening(Int32 to Decimal)Converts a 32-bit signed integer to a Decimal.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360Widening(Int64 to Decimal)Converts a 64-bit signed integer to a Decimal.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360Widening(SByte to Decimal)Converts an 8-bit signed integer to a Decimal.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360Widening(UInt16 to Decimal)Converts a 16-bit unsigned integer to a Decimal.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360Widening(UInt32 to Decimal)Converts a 32-bit unsigned integer to a Decimal.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360Widening(UInt64 to Decimal)Converts a 64-bit unsigned integer to a Decimal.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360IncrementIncrements the Decimal operand by 1.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360InequalityReturns a value indicating whether two instances of Decimal are not equal.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360LessThanReturns a value indicating whether a specified Decimal is less than another specified Decimal.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360LessThanOrEqualReturns a value indicating whether a specified Decimal is less than or equal to another specified Decimal.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360ModulusReturns the remainder resulting from dividing two specified Decimal values.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360MultiplyMultiplies two specified Decimal values.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360SubtractionSubtracts two specified Decimal values.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360UnaryNegationNegates the value of the specified Decimal operand.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360UnaryPlusReturns the value of the Decimal operand (the sign of the operand is unchanged).
Top

  NameDescription
Public fieldStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360MaxValueRepresents the largest possible value of Decimal. This field is constant and read-only.
Public fieldStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360MinusOneRepresents the number negative one (-1).
Public fieldStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360MinValueRepresents the smallest possible value of Decimal. This field is constant and read-only.
Public fieldStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360OneRepresents the number one (1).
Public fieldStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360ZeroRepresents the number zero (0).
Top

  NameDescription
Explicit interface implemetationPrivate methodSupported by Silverlight for Windows PhoneSupported by Xbox 360IConvertible.ToBooleanInfrastructure. For a description of this member, see IConvertible.ToBoolean.
Explicit interface implemetationPrivate methodSupported by Silverlight for Windows PhoneSupported by Xbox 360IConvertible.ToByteInfrastructure. For a description of this member, see IConvertible.ToByte.
Explicit interface implemetationPrivate methodSupported by Silverlight for Windows PhoneSupported by Xbox 360IConvertible.ToCharInfrastructure. This conversion is not supported. Attempting to use this method throws an InvalidCastException.
Explicit interface implemetationPrivate methodSupported by Silverlight for Windows PhoneSupported by Xbox 360IConvertible.ToDateTimeInfrastructure. This conversion is not supported. Attempting to use this method throws an InvalidCastException.
Explicit interface implemetationPrivate methodSupported by Silverlight for Windows PhoneSupported by Xbox 360IConvertible.ToDecimalInfrastructure. For a description of this member, see IConvertible.ToDecimal.
Explicit interface implemetationPrivate methodSupported by Silverlight for Windows PhoneSupported by Xbox 360IConvertible.ToDoubleInfrastructure. For a description of this member, see IConvertible.ToDouble.
Explicit interface implemetationPrivate methodSupported by Silverlight for Windows PhoneSupported by Xbox 360IConvertible.ToInt16Infrastructure. For a description of this member, see IConvertible.ToInt16.
Explicit interface implemetationPrivate methodSupported by Silverlight for Windows PhoneSupported by Xbox 360IConvertible.ToInt32Infrastructure. For a description of this member, see IConvertible.ToInt32.
Explicit interface implemetationPrivate methodSupported by Silverlight for Windows PhoneSupported by Xbox 360IConvertible.ToInt64Infrastructure. For a description of this member, see IConvertible.ToInt64.
Explicit interface implemetationPrivate methodSupported by Silverlight for Windows PhoneSupported by Xbox 360IConvertible.ToSByteInfrastructure. For a description of this member, see IConvertible.ToSByte.
Explicit interface implemetationPrivate methodSupported by Silverlight for Windows PhoneSupported by Xbox 360IConvertible.ToSingleInfrastructure. For a description of this member, see IConvertible.ToSingle.
Explicit interface implemetationPrivate methodSupported by Silverlight for Windows PhoneSupported by Xbox 360IConvertible.ToTypeInfrastructure. For a description of this member, see IConvertible.ToType.
Explicit interface implemetationPrivate methodSupported by Silverlight for Windows PhoneSupported by Xbox 360IConvertible.ToUInt16Infrastructure. For a description of this member, see IConvertible.ToUInt16.
Explicit interface implemetationPrivate methodSupported by Silverlight for Windows PhoneSupported by Xbox 360IConvertible.ToUInt32Infrastructure. For a description of this member, see IConvertible.ToInt32.
Explicit interface implemetationPrivate methodSupported by Silverlight for Windows PhoneSupported by Xbox 360IConvertible.ToUInt64Infrastructure. For a description of this member, see IConvertible.ToInt64.
Top

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. 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 rather than 1.


Dim dividend As Decimal = Decimal.One
Dim divisor As Decimal = 3
' The following displays 0.9999999999999999999999999999
outputBlock.Text &= dividend / divisor * divisor & vbCrLf


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.


Dim dividend As Decimal = Decimal.One
Dim divisor As Decimal = 3
' The following displays 1.00
outputBlock.Text += Math.Round(dividend / divisor * divisor, 2) & vbCrLf


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 is of the form, ((-296 to 296) / 10(0 to 28)), where -296-1 is equal to MinValue, and 296-1 is equal to MaxValue.

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

Conversion Considerations

This type provides methods that convert Decimal values to and from SByte, Int16, Int32, Int64, Byte, UInt16, UInt32, and UInt64. 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 is thrown.

The Decimal type also 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 cannot be represented as a Decimal.

Implemented Interfaces

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

The following code example demonstrates the use of Decimal.


' Keeping my fortune in Decimals to avoid the round-off errors.
Class PiggyBank
   Protected MyFortune As Decimal

   Public Sub AddPenny()
      MyFortune = [Decimal].Add(MyFortune, 0.01D)
   End Sub

   Public ReadOnly Property Capacity() As Decimal
      Get
         Return [Decimal].MaxValue
      End Get
   End Property

   Public ReadOnly Property Dollars() As Decimal
      Get
         Return [Decimal].Floor(MyFortune)
      End Get
   End Property

   Public ReadOnly Property Cents() As Decimal
      Get
         Return [Decimal].Subtract(MyFortune, [Decimal].Floor(MyFortune))
      End Get
   End Property

   Public Overrides Function ToString() As String
      Return MyFortune.ToString("C") + " in piggy bank"
   End Function
End Class


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

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.

Caution noteCaution:

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.

Community Additions

Show:
© 2014 Microsoft