Export (0) Print
Expand All

Decimal.Subtract Method

Subtracts one specified Decimal value from another.

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

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

Parameters

d1

A Decimal (the minuend).

d2

A Decimal (the subtrahend).

Return Value

The Decimal result of subtracting d2 from d1.

Exception typeCondition

OverflowException

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

The following code sample illustrates the use of Subtract :

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

    protected decimal MyFortune;

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

class PiggyBank
{
    /** @property 
     */
    public System.Decimal get_Cents()
    {
        return System.Decimal.Subtract(myFortune, 
            System.Decimal.Floor(myFortune));
    } //get_Cents

    protected System.Decimal myFortune;

    public void AddPenny()
    {
        myFortune.Add(myFortune, System.Convert.ToDecimal(0.01));
    } //AddPenny
} //PiggyBank

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);
    }
}

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft