Compartir a través de


Decimal.Subtract Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Subtracts one specified Decimal value from another.

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

Syntax

'Declaration
<SecuritySafeCriticalAttribute> _
Public Shared Function Subtract ( _
    d1 As Decimal, _
    d2 As Decimal _
) As Decimal
[SecuritySafeCriticalAttribute]
public static decimal Subtract(
    decimal d1,
    decimal d2
)

Parameters

Return Value

Type: System.Decimal
The Decimal result of subtracting d2 from d1.

Exceptions

Exception Condition
OverflowException

The return value is less than MinValue or greater than MaxValue.

Examples

The following example illustrates the use of Subtract.

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

   Protected MyFortune As Decimal

   Public Sub AddPenny()
      MyFortune += 0.01D
   End Sub
End Class
class PiggyBank
{
   public decimal Cents
   {
      get
      {
         return Decimal.Subtract(MyFortune, Decimal.Floor(MyFortune));
      }
   }

   protected decimal MyFortune;

   public void AddPenny()
   {
      MyFortune += .01m;
   }
}

Version Information

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

Platforms

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