This documentation is archived and is not being maintained.

Decimal.Subtract Method

Subtracts one specified Decimal value from another.

[Visual Basic]
Public Shared Function Subtract( _
   ByVal d1 As Decimal, _
   ByVal d2 As Decimal _
) As Decimal
public static decimal Subtract(
 decimal d1,
 decimal d2
public: static Decimal Subtract(
 Decimal d1,
 Decimal d2
public static function Subtract(
   d1 : Decimal,
 d2 : Decimal
) : Decimal;


A Decimal (the minuend).
A Decimal (the subtrahend).

Return Value

The Decimal result of subtracting d2 from d1.


Exception Type Condition
OverflowException The return value is less than MinValue or greater than MaxValue.


The following code sample illustrates the use of Subtract:

[Visual Basic] 
Class PiggyBank
    Public ReadOnly Property Cents() As Decimal
            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;

public __gc class PiggyBank {
    Decimal Cents() {
        return Decimal::Subtract(MyFortune, Decimal::Floor(MyFortune));

    void AddPenny() {
        Decimal::op_Addition(MyFortune, .01);
    Decimal MyFortune;

class PiggyBank {
    public function get Cents() : Decimal {
        return Decimal.Subtract(MyFortune, Decimal.Floor(MyFortune));

    protected var MyFortune : Decimal;

    public function AddPenny() {
        MyFortune = Decimal.Add(MyFortune, 0.01);


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

Decimal Structure | Decimal Members | System Namespace | Add | Multiply | Divide