Decimal.Modulus(Decimal, Decimal) Decimal.Modulus(Decimal, Decimal) Decimal.Modulus(Decimal, Decimal) Decimal.Modulus(Decimal, Decimal) Operator

定義

傳回從兩個指定的 Decimal 值相除所得的餘數。Returns the remainder resulting from dividing two specified Decimal values.

public:
 static System::Decimal operator %(System::Decimal d1, System::Decimal d2);
public static decimal operator % (decimal d1, decimal d2);
static member ( % ) : decimal * decimal -> decimal
Public Shared Operator Mod (d1 As Decimal, d2 As Decimal) As Decimal

參數

d1
Decimal Decimal Decimal Decimal

被除數。The dividend.

d2
Decimal Decimal Decimal Decimal

除數。The divisor.

傳回

d1 除以 d2 所得的餘數。The remainder resulting from dividing d1 by d2.

例外狀況

傳回值小於 MinValue 或大於 MaxValueThe return value is less than MinValue or greater than MaxValue.

備註

運算子定義餘數運算,此作業會傳回兩個指定Decimal值相除所得的餘數。 ModulusThe Modulus operator defines the remainder operation that returns the remainder resulting from dividing two specified Decimal values. 它會啟用如下所示的程式碼:It enables code such as the following:

using System;

public class Example
{
   public static void Main()
   {
      Decimal number1 = 16.8m;
      Decimal number2 = 4.1m;
      Decimal number3 = number1 % number2;
      Console.WriteLine("{0:N2} % {1:N2} = {2:N2}", 
                        number1, number2, number3);
   }
}
// The example displays the following output:
//        16.80 % 4.10 = 0.40
Module Example
   Public Sub Main()
      Dim number1 As Decimal = 16.8d 
      Dim number2 As Decimal = 4.1d 
      Dim number3 As Decimal = number1 Mod number2
      Console.WriteLine("{0:N2} Mod {1:N2} = {2:N2}", 
                        number1, number2, number3)
   End Sub
End Module
' The example displays the following output:
'       16.80 Mod 4.10 = 0.40

餘數運算所傳回之值的正負號取決於被除數的正負號。The sign of the value returned by the remainder operation depends on the sign of dividend. 如果被除數為正數,餘數作業會傳回正的結果;如果是負數,餘數作業會傳回負的結果。If dividend is positive, the remainder operation returns a positive result; if it is negative, the remainder operation returns a negative result.

這個運算子的對等方法是Decimal.Remainder(Decimal, Decimal)The equivalent method for this operator is Decimal.Remainder(Decimal, Decimal). 如果您所使用的語言不支援自訂運算子,請Remainder改為呼叫方法。If the language you're using doesn't support custom operators, call the Remainder method instead.

適用於

另請參閱