This documentation is archived and is not being maintained.

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
Not applicable.



A Decimal (the minuend).


A Decimal (the subtrahend).

Return Value

The Decimal result of subtracting d2 from d1.

Exception typeCondition


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

The following example 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, 
    } //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 Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0