Decimal.Subtract(Decimal, Decimal) Methode

Definition

Subtrahiert einen angegebenen Decimal-Wert von einem anderen.

public:
 static System::Decimal Subtract(System::Decimal d1, System::Decimal d2);
public static decimal Subtract (decimal d1, decimal d2);
static member Subtract : decimal * decimal -> decimal
Public Shared Function Subtract (d1 As Decimal, d2 As Decimal) As Decimal

Parameter

d1
Decimal

Der Minuend.

d2
Decimal

Der Subtrahend.

Gibt zurück

Das Ergebnis der Subtraktion von d2 von d1.

Ausnahmen

Der Rückgabewert ist kleiner als Decimal.MinValue oder größer als Decimal.MaxValue.

Beispiele

Im folgenden Beispiel wird die Verwendung von Subtract veranschaulicht.

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

      void AddPenny()
      {
         MyFortune = Decimal::Add(MyFortune, (Decimal).01);
      }

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

    protected decimal MyFortune;

    public void AddPenny() {
        MyFortune += .01m;
    }
}
type PiggyBank() =
    let mutable myFortune = 0m

    member _.Cents =
        Decimal.Subtract(myFortune, Decimal.Floor myFortune)

    member _.AddPenny() =
        myFortune <- myFortune + 0.01m
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

Gilt für:

Weitere Informationen